Repository navigation
feat(ui): add Mosaic table, checkbox and empty state components #9789
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
Changes from all commits
aaa6fa4
23dcc6c
ca0b3ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
|
Comment on lines
+1
to
+2
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dumb question, but do we only need to add to changelog if user button is affected since that's the only exported thing from the package rn?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not dumb at all. The changeset is a changelog entry for people upgrading
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh. thanks for the explanation 😌 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| export const checkboxInputMarker = stylex.defineMarker(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
|
|
||
| import { colorVars, durationVars, radiusVars, space } from '../../tokens.stylex'; | ||
| import { checkboxInputMarker } from './checkbox.markers.stylex'; | ||
|
|
||
| const hoverBorderColor = 'light-dark(#bebebe, #525252)'; | ||
|
|
||
| export const styles = stylex.create({ | ||
| root: { | ||
| display: 'inline-flex', | ||
| flexShrink: 0, | ||
| position: 'relative', | ||
| verticalAlign: 'middle', | ||
| }, | ||
| input: { | ||
|
alexcarpenter marked this conversation as resolved.
|
||
| borderColor: { | ||
| default: colorVars['--cl-color-border'], | ||
| ':checked': colorVars['--cl-color-brand'], | ||
| ':indeterminate': colorVars['--cl-color-brand'], | ||
| '@media (hover: hover)': { | ||
| ':hover:not(:disabled):not(:checked):not(:indeterminate)': hoverBorderColor, | ||
| }, | ||
| }, | ||
| borderRadius: radiusVars['--cl-radius-sm'], | ||
| borderStyle: 'solid', | ||
| borderWidth: '1px', | ||
| appearance: 'none', | ||
| backgroundColor: { | ||
| default: colorVars['--cl-color-background'], | ||
| ':checked': colorVars['--cl-color-brand'], | ||
| ':indeterminate': colorVars['--cl-color-brand'], | ||
| }, | ||
| cursor: { default: 'pointer', ':disabled': 'not-allowed' }, | ||
| display: 'block', | ||
| flexShrink: 0, | ||
| opacity: { default: null, ':disabled': 0.5 }, | ||
| position: 'relative', | ||
| transitionDuration: durationVars['--cl-duration-fast'], | ||
| transitionProperty: 'background-color, border-color', | ||
| transitionTimingFunction: 'linear', | ||
| }, | ||
| hitTarget: { | ||
| '::before': { | ||
| inset: `calc(-1 * ${space['3']})`, | ||
| content: '""', | ||
| display: { default: 'none', '@media (pointer: coarse)': 'block' }, | ||
| position: 'absolute', | ||
| }, | ||
| }, | ||
| indicator: { | ||
| inset: 0, | ||
| alignItems: 'center', | ||
| color: colorVars['--cl-color-brand-foreground'], | ||
| display: 'none', | ||
| justifyContent: 'center', | ||
| pointerEvents: 'none', | ||
| position: 'absolute', | ||
| }, | ||
| checkedIndicator: { | ||
| display: { | ||
| default: 'none', | ||
| [stylex.when.siblingBefore(':checked:not(:indeterminate)', checkboxInputMarker)]: 'flex', | ||
| }, | ||
| }, | ||
| indeterminateIndicator: { | ||
| display: { | ||
| default: 'none', | ||
| [stylex.when.siblingBefore(':indeterminate', checkboxInputMarker)]: 'flex', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const sizes = stylex.create({ | ||
| sm: { height: space['3.5'], width: space['3.5'] }, | ||
| md: { height: space['4'], width: space['4'] }, | ||
| }); | ||
|
|
||
| export const indicatorSizes = stylex.create({ | ||
| sm: { fontSize: space['2.5'] }, | ||
| md: { fontSize: space['3'] }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import * as stylex from '@stylexjs/stylex'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import React from 'react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { Checkbox } from './checkbox'; | ||
| import { styles } from './checkbox.styles'; | ||
|
|
||
| const atoms = stylex.create({ | ||
| spaced: { marginTop: '8px' }, | ||
| }); | ||
|
|
||
| describe('Mosaic Checkbox', () => { | ||
| it('renders a native checkbox wrapped in the slot element', () => { | ||
| render(<Checkbox aria-label='Select row' />); | ||
| const input = screen.getByRole('checkbox', { name: 'Select row' }); | ||
| expect(input).toHaveClass('cl-checkbox-input'); | ||
| expect(input.parentElement).toHaveClass('cl-checkbox'); | ||
| }); | ||
|
|
||
| it('toggles and reports changes', async () => { | ||
| const onChange = vi.fn(); | ||
| render( | ||
| <Checkbox | ||
| aria-label='Select row' | ||
| onChange={onChange} | ||
| />, | ||
| ); | ||
| const input = screen.getByRole('checkbox'); | ||
| await userEvent.click(input); | ||
| expect(input).toBeChecked(); | ||
| expect(onChange).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('supports a controlled checked state', () => { | ||
| render( | ||
| <Checkbox | ||
| aria-label='Select row' | ||
| checked | ||
| onChange={() => {}} | ||
| />, | ||
| ); | ||
| expect(screen.getByRole('checkbox')).toBeChecked(); | ||
| }); | ||
|
|
||
| it('applies the indeterminate state through the DOM property', () => { | ||
| const { rerender } = render( | ||
| <Checkbox | ||
| aria-label='Select all' | ||
| indeterminate | ||
| />, | ||
| ); | ||
| const input = screen.getByRole<HTMLInputElement>('checkbox'); | ||
| expect(input.indeterminate).toBe(true); | ||
|
|
||
| rerender(<Checkbox aria-label='Select all' />); | ||
| expect(input.indeterminate).toBe(false); | ||
| }); | ||
|
|
||
| it('reflects the size axis on the slot element', () => { | ||
| render(<Checkbox aria-label='Select row' />); | ||
| expect(screen.getByRole('checkbox').parentElement).toHaveAttribute('data-size', 'md'); | ||
| }); | ||
|
|
||
| it('disables the input', () => { | ||
| render( | ||
| <Checkbox | ||
| aria-label='Select row' | ||
| disabled | ||
| />, | ||
| ); | ||
| expect(screen.getByRole('checkbox')).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('merges xstyle atoms onto the slot element', () => { | ||
| render( | ||
| <Checkbox | ||
| aria-label='Select row' | ||
| xstyle={atoms.spaced} | ||
| />, | ||
| ); | ||
| expect(screen.getByRole('checkbox').parentElement).toHaveClass( | ||
| 'cl-checkbox', | ||
| stylex.props(atoms.spaced).className ?? '', | ||
| ); | ||
| }); | ||
|
|
||
| it('widens the hit target on the input for coarse pointers', () => { | ||
| render(<Checkbox aria-label='Select row' />); | ||
| expect(screen.getByRole('checkbox')).toHaveClass(stylex.props(styles.hitTarget).className ?? ''); | ||
| }); | ||
|
|
||
| it('forwards the ref and arbitrary input props to the input', () => { | ||
| const ref = React.createRef<HTMLInputElement>(); | ||
| render( | ||
| <Checkbox | ||
| ref={ref} | ||
| aria-label='Select row' | ||
| name='rows' | ||
| value='1' | ||
| />, | ||
| ); | ||
| const input = screen.getByRole('checkbox'); | ||
| expect(ref.current).toBe(input); | ||
| expect(input).toHaveAttribute('name', 'rows'); | ||
| expect(input).toHaveAttribute('value', '1'); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.