-
Notifications
You must be signed in to change notification settings - Fork 11
feat(Interaction): new Interaction component
#617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
noahchoii
wants to merge
27
commits into
main
Choose a base branch
from
interaction-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3c805e6
docs: add Interaction component design spec
noahchoii a8d1654
docs: add Interaction component implementation plan
noahchoii 8766207
feat(Interaction): add interaction recipe
noahchoii 98ad693
feat(Interaction): add component skeleton with Slot pattern
noahchoii 889bfcf
feat(Interaction): apply recipe className to child
noahchoii 07fccfb
test(Interaction): preserve child className when merging
noahchoii 9288845
feat(Interaction): merge external className prop
noahchoii af26639
feat(Interaction): wire scale and type variant props
noahchoii 2a54b48
test(Interaction): cover multi-child and non-element error cases
noahchoii 78bbdbb
test(Interaction): verify ref forwarding through cloneElement
noahchoii 32e1b1a
test(Interaction): add vitest-axe smoke check
noahchoii 4ade60f
feat(Interaction): add component entrypoint
noahchoii 8748f3d
docs(Interaction): add Storybook stories
noahchoii 2e613a0
feat(Interaction): re-export from package root
noahchoii a0c18ef
cleanup & edit css
noahchoii 278b2c1
change dataset attributes
noahchoii 451c925
adjust Interaction component
noahchoii 0f09917
update snapshot
noahchoii 660e4f9
remove docs
noahchoii 4e97b5c
cleanup test cases
noahchoii eab4829
install storybook-addon-pseudo-states
noahchoii 081d7ab
enhance interaction testbed
noahchoii 2930624
update snapshot
noahchoii 587c538
propagate child.props.children
noahchoii 9ce3d9a
adjust Interaction to missed components
noahchoii a3ac0c3
Merge branch main into interaction-component
noahchoii 4e5d36c
Merge branch 'main' into interaction-component
noahchoii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+12.7 KB
packages/core/__tests__/screenshots/interaction--test-bed-1-chrome-darwin-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.7 KB
packages/core/__tests__/screenshots/interaction--test-bed-1-edge-darwin-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28 KB
packages/core/__tests__/screenshots/interaction--test-bed-1-firefox-darwin-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.7 KB
packages/core/__tests__/screenshots/interaction--test-bed-1-safari-darwin-.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './interaction'; |
94 changes: 94 additions & 0 deletions
94
packages/core/src/components/interaction/interaction.css.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { createGlobalVar } from '@vanilla-extract/css'; | ||
| import { calc } from '@vanilla-extract/css-utils'; | ||
| import type { RecipeVariants } from '@vanilla-extract/recipes'; | ||
|
|
||
| import { componentRecipe, componentStyle } from '~/styles/mixins/layer-style.css'; | ||
| import { vars } from '~/styles/themes.css'; | ||
|
|
||
| const variables = { | ||
| ratio: createGlobalVar('ratio'), | ||
| opacity: createGlobalVar('overlay-opacity'), | ||
| }; | ||
|
|
||
| export const overlay = componentStyle({ | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| transition: 'opacity 150ms ease', | ||
| opacity: variables.opacity, | ||
| border: 'none', | ||
| borderRadius: 'inherit', | ||
| backgroundColor: vars.color.gray[900], | ||
| pointerEvents: 'none', | ||
| width: '100%', | ||
| height: '100%', | ||
| }); | ||
|
|
||
| export const root = componentRecipe({ | ||
| base: { | ||
| position: 'relative', | ||
| selectors: { | ||
| '&:focus': { outline: 'none' }, | ||
| '&:focus-visible': { outline: 'none' }, | ||
| }, | ||
| vars: { | ||
| [variables.ratio]: '0.08', | ||
| [variables.opacity]: '0', | ||
| }, | ||
| }, | ||
| defaultVariants: { scale: 'normal', type: 'default' }, | ||
| variants: { | ||
| scale: { | ||
| normal: {}, | ||
| light: { vars: { [variables.ratio]: '0.04' } }, | ||
| }, | ||
| type: { | ||
| default: { | ||
| selectors: { | ||
| '&:active': { | ||
| vars: { [variables.opacity]: calc.multiply(variables.ratio, 2) }, | ||
| }, | ||
| '&:focus-visible': { | ||
| outline: `2px solid ${vars.color.foreground.normal[200]}`, | ||
| outlineOffset: '2px', | ||
| }, | ||
| }, | ||
| '@media': { | ||
| '(hover: hover)': { | ||
| selectors: { | ||
| '&:hover': { vars: { [variables.opacity]: variables.ratio } }, | ||
| '&:active': { | ||
| vars: { [variables.opacity]: calc.multiply(variables.ratio, 2) }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| form: { | ||
| transition: 'box-shadow 150ms cubic-bezier(.4,0,.2,1)', | ||
| selectors: { | ||
| '&:focus': { | ||
| boxShadow: `inset 0 0 0 0.0625rem ${vars.color.border.primary}`, | ||
| }, | ||
| }, | ||
| '@media': { | ||
| '(hover: hover)': { | ||
| selectors: { | ||
| '&:hover:not(:focus)': { | ||
| boxShadow: `inset 0 0 0 0.0625rem color-mix(in srgb, ${vars.color.gray[900]} 32%, transparent)`, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| roving: { | ||
| selectors: { | ||
| '&[data-highlighted]': { vars: { [variables.opacity]: '0.08' } }, | ||
| '&[data-highlighted]:active': { vars: { [variables.opacity]: '0.16' } }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export type InteractionVariants = NonNullable<RecipeVariants<typeof root>>; |
109 changes: 109 additions & 0 deletions
109
packages/core/src/components/interaction/interaction.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import type { CSSProperties } from 'react'; | ||
|
|
||
| import type { Meta, StoryObj } from '@storybook/react-vite'; | ||
|
|
||
| import { Interaction } from './interaction'; | ||
|
|
||
| export default { | ||
| title: 'Interaction', | ||
| component: Interaction, | ||
| argTypes: { | ||
| scale: { control: 'inline-radio', options: ['normal', 'light'] }, | ||
| type: { control: 'inline-radio', options: ['default', 'form', 'roving'] }, | ||
| }, | ||
| } as Meta<typeof Interaction>; | ||
|
|
||
| type Story = StoryObj<typeof Interaction>; | ||
|
|
||
| const buttonStyle: CSSProperties = { | ||
| padding: '0.5rem 1rem', | ||
| border: '1px solid #ccc', | ||
| borderRadius: '0.375rem', | ||
| background: '#fff', | ||
| cursor: 'pointer', | ||
| }; | ||
|
|
||
| const inputStyle: CSSProperties = { | ||
| padding: '0.5rem 0.75rem', | ||
| border: '1px solid #ccc', | ||
| borderRadius: '0.375rem', | ||
| outline: 'none', | ||
| }; | ||
|
|
||
| const itemStyle: CSSProperties = { | ||
| padding: '0.5rem 0.75rem', | ||
| borderRadius: '0.375rem', | ||
| userSelect: 'none', | ||
| cursor: 'pointer', | ||
| }; | ||
|
|
||
| export const Default: Story = { | ||
| render: (args) => ( | ||
| <Interaction {...args}> | ||
| <button type="button" style={buttonStyle}> | ||
| Interactive button | ||
| </button> | ||
| </Interaction> | ||
| ), | ||
| }; | ||
|
|
||
| export const ScaleLight: Story = { | ||
| args: { scale: 'light' }, | ||
| render: (args) => ( | ||
| <Interaction {...args}> | ||
| <button type="button" style={buttonStyle}> | ||
| Light scale | ||
| </button> | ||
| </Interaction> | ||
| ), | ||
| }; | ||
|
|
||
| export const TypeForm: Story = { | ||
| args: { type: 'form' }, | ||
| render: (args) => ( | ||
| <Interaction {...args}> | ||
| <input type="text" placeholder="Form input" style={inputStyle} /> | ||
| </Interaction> | ||
| ), | ||
| }; | ||
|
|
||
| export const TypeRoving: Story = { | ||
| args: { type: 'roving' }, | ||
| render: (args) => ( | ||
| <div style={{ display: 'flex', flexDirection: 'column', gap: '0.25rem' }}> | ||
| <Interaction {...args}> | ||
| <div data-highlighted style={itemStyle}> | ||
| Highlighted item | ||
| </div> | ||
| </Interaction> | ||
| <Interaction {...args}> | ||
| <div style={itemStyle}>Regular item</div> | ||
| </Interaction> | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| export const TestBed: Story = { | ||
| render: () => ( | ||
| <div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}> | ||
| <Interaction> | ||
| <button type="button" style={buttonStyle}> | ||
| default / normal | ||
| </button> | ||
| </Interaction> | ||
| <Interaction scale="light"> | ||
| <button type="button" style={buttonStyle}> | ||
| default / light | ||
| </button> | ||
| </Interaction> | ||
| <Interaction type="form"> | ||
| <input type="text" placeholder="form / normal" style={inputStyle} /> | ||
| </Interaction> | ||
| <Interaction type="roving"> | ||
| <div data-highlighted style={itemStyle}> | ||
| roving (highlighted) | ||
| </div> | ||
| </Interaction> | ||
| </div> | ||
| ), | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.