-
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): Adding select atom (#876)
* Feat: adding select atom
- Loading branch information
Showing
8 changed files
with
141 additions
and
2 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 |
---|---|---|
|
@@ -55,3 +55,4 @@ | |
"@typescript-eslint/parser": "^4" | ||
} | ||
} | ||
|
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 { render } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import Select from './Select' | ||
|
||
const optionsArray = [ | ||
['great', 'Great'], | ||
['ok', 'Ok'], | ||
['bad', 'Bad'], | ||
] | ||
|
||
const mapPairToOption = (value: string, label: string) => { | ||
return ( | ||
<option key={value} value={value}> | ||
{label} | ||
</option> | ||
) | ||
} | ||
|
||
describe('Select', () => { | ||
it('`data-store-select` is present', () => { | ||
const { getByTestId } = render( | ||
<Select testId="store-select"> | ||
{optionsArray.map(([value, label]) => { | ||
return mapPairToOption(value, label) | ||
})} | ||
</Select> | ||
) | ||
|
||
expect(getByTestId('store-select')).toHaveAttribute('data-store-select') | ||
}) | ||
|
||
it('select is empty when no options are given', () => { | ||
const { getByTestId } = render(<Select testId="store-select" />) | ||
|
||
expect(getByTestId('store-select')).toBeEmptyDOMElement() | ||
}) | ||
}) |
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,22 @@ | ||
import type { SelectHTMLAttributes } from 'react' | ||
import React, { forwardRef } from 'react' | ||
|
||
export interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> { | ||
/** | ||
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest). | ||
*/ | ||
testId?: string | ||
} | ||
|
||
const Select = forwardRef<HTMLSelectElement, SelectProps>(function Select( | ||
{ children, testId = 'store-select', ...props }, | ||
ref | ||
) { | ||
return ( | ||
<select ref={ref} data-store-select data-testid={testId} {...props}> | ||
{children} | ||
</select> | ||
) | ||
}) | ||
|
||
export default Select |
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 './Select' | ||
export type { SelectProps } from './Select' |
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 Select from '../Select' | ||
|
||
# Default | ||
|
||
<Canvas> | ||
<Story id="atoms-select--select" /> | ||
</Canvas> | ||
|
||
# Props | ||
|
||
<ArgsTable of={Select} /> |
59 changes: 59 additions & 0 deletions
59
packages/store-ui/src/atoms/Select/stories/Select.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,59 @@ | ||
import type { Story } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import type { ComponentArgTypes } from '../../../typings/utils' | ||
import type { SelectProps } from '../Select' | ||
import Component from '../Select' | ||
import mdx from './Select.mdx' | ||
|
||
const SelectTemplate: Story<SelectProps> = ({ options, ...props }) => { | ||
return ( | ||
<Component {...props}> | ||
{options.map(([value, label]) => { | ||
return ( | ||
<option key={value} value={value}> | ||
{label} | ||
</option> | ||
) | ||
})} | ||
</Component> | ||
) | ||
} | ||
|
||
export const DefaultSelect = SelectTemplate.bind({}) | ||
|
||
export const DisabledSelect = SelectTemplate.bind({}) | ||
DisabledSelect.args = { | ||
disabled: true, | ||
} | ||
|
||
export const MultipleSelect = SelectTemplate.bind({}) | ||
MultipleSelect.args = { | ||
multiple: true, | ||
} | ||
|
||
export const BaseValueSelect = SelectTemplate.bind({}) | ||
BaseValueSelect.args = { | ||
defaultValue: 'ok', | ||
} | ||
|
||
const argTypes: ComponentArgTypes<SelectProps> = { | ||
options: { | ||
control: { type: 'array' }, | ||
defaultValue: [ | ||
['great', 'Great'], | ||
['ok', 'Ok'], | ||
['bad', 'Bad'], | ||
], | ||
}, | ||
} | ||
|
||
export default { | ||
title: 'Atoms/Select', | ||
argTypes, | ||
parameters: { | ||
docs: { | ||
page: mdx, | ||
}, | ||
}, | ||
} |
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
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