-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-ui): Checkbox atom component (#813)
* Add checkbox atom component * Change the default testId value * Add actions and controls to Checkbox component * Fix test ids from test
- Loading branch information
1 parent
1cd8916
commit 36834fa
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,18 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
|
||
import Checkbox from './Checkbox' | ||
|
||
describe('Checkbox', () => { | ||
it('data-store-checkbox is present', () => { | ||
const { getByTestId } = render(<Checkbox testId="store-checkbox" />) | ||
|
||
expect(getByTestId('store-checkbox')).toHaveAttribute('data-store-checkbox') | ||
}) | ||
|
||
it('type checkbox is present', () => { | ||
const { getByTestId } = render(<Checkbox testId="store-checkbox" />) | ||
|
||
expect(getByTestId('store-checkbox')).toHaveAttribute('type', 'checkbox') | ||
}) | ||
}) |
This file contains 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,24 @@ | ||
import React, { forwardRef } from 'react' | ||
import type { InputHTMLAttributes } from 'react' | ||
|
||
export interface Props | ||
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> { | ||
testId?: string | ||
} | ||
|
||
const Checkbox = forwardRef<HTMLInputElement, Props>(function Checkbox( | ||
{ testId = 'store-checkbox', ...props }: Props, | ||
ref | ||
) { | ||
return ( | ||
<input | ||
ref={ref} | ||
data-store-checkbox | ||
data-testid={testId} | ||
type="checkbox" | ||
{...props} | ||
/> | ||
) | ||
}) | ||
|
||
export default Checkbox |
This file contains 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,2 @@ | ||
export { default } from './Checkbox' | ||
export * from './Checkbox' |
This file contains 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,12 @@ | ||
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs' | ||
import Checkbox from '../Checkbox' | ||
|
||
# Preview | ||
|
||
<Canvas> | ||
<Story id="atoms-checkbox--checkbox" /> | ||
</Canvas> | ||
|
||
# Props | ||
|
||
<ArgsTable of="Checkbox" /> |
38 changes: 38 additions & 0 deletions
38
packages/store-ui/src/atoms/Checkbox/stories/Checkbox.stories.tsx
This file contains 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,38 @@ | ||
import type { Story, Meta, ArgTypes } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import type { Props as CheckboxProps } from '../Checkbox' | ||
import Component from '../Checkbox' | ||
import mdx from './Checkbox.mdx' | ||
|
||
const CheckboxTemplate: Story<CheckboxProps> = (props) => ( | ||
<Component {...props} /> | ||
) | ||
|
||
export const Checkbox = CheckboxTemplate.bind({}) | ||
|
||
const controls: ArgTypes = { | ||
checked: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
} | ||
|
||
const actions: ArgTypes = { | ||
onClick: { action: 'clicked', table: { disable: true } }, | ||
} | ||
|
||
export default { | ||
title: 'Atoms/Checkbox', | ||
component: Checkbox, | ||
argTypes: { | ||
...controls, | ||
...actions, | ||
}, | ||
parameters: { | ||
docs: { | ||
page: mdx, | ||
}, | ||
}, | ||
} as Meta |