-
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.
- Loading branch information
Bento Pereira
committed
Aug 3, 2021
1 parent
3c45213
commit ed6ddff
Showing
5 changed files
with
114 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,30 @@ | ||
import { render } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import Input from '.' | ||
|
||
describe('Input', () => { | ||
it('`data-store-input` is present', () => { | ||
const { getByPlaceholderText } = render( | ||
<Input placeholder="Hello World!" /> | ||
) | ||
|
||
expect(getByPlaceholderText('Hello World!')).toHaveAttribute( | ||
'data-store-input' | ||
) | ||
}) | ||
it('`data-error` is present', () => { | ||
const { getByPlaceholderText } = render( | ||
<Input placeholder="Hello World!" variant="error" /> | ||
) | ||
|
||
expect(getByPlaceholderText('Hello World!')).toHaveAttribute('data-error') | ||
}) | ||
it('`data-success` is present', () => { | ||
const { getByPlaceholderText } = render( | ||
<Input placeholder="Hello World!" variant="success" /> | ||
) | ||
|
||
expect(getByPlaceholderText('Hello World!')).toHaveAttribute('data-success') | ||
}) | ||
}) |
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,19 @@ | ||
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ | ||
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( | ||
{ testId = 'store-select', ...props }, | ||
ref | ||
) { | ||
return <select ref={ref} data-store-select data-testid={testId} {...props} /> | ||
}) | ||
|
||
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 Input from '../Input' | ||
|
||
# Default | ||
|
||
<Canvas> | ||
<Story id="atoms-input--input" /> | ||
</Canvas> | ||
|
||
# Props | ||
|
||
<ArgsTable of={Input} /> |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
import type { Story } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import type { ComponentArgTypes } from '../../../typings/utils' | ||
import type { InputProps } from '../Input' | ||
import Component from '../Input' | ||
import mdx from './Input.mdx' | ||
|
||
const InputTemplate: Story<InputProps> = ({ placeholder, variant }) => { | ||
const colorByVariant = { | ||
default: 'black', | ||
success: 'green', | ||
error: 'red', | ||
} | ||
|
||
return ( | ||
<Component | ||
style={{ | ||
borderColor: colorByVariant[variant || 'default'], | ||
borderStyle: 'solid', | ||
}} | ||
placeholder={placeholder} | ||
variant={variant} | ||
/> | ||
) | ||
} | ||
|
||
export const Input = InputTemplate.bind({}) | ||
|
||
const argTypes: ComponentArgTypes<InputProps> = { | ||
variant: { | ||
options: ['default', 'success', 'error'], | ||
defaultValue: 'default', | ||
control: { type: 'select' }, | ||
}, | ||
placeholder: { | ||
control: { type: 'text' }, | ||
defaultValue: 'Input', | ||
}, | ||
} | ||
|
||
export default { | ||
title: 'Atoms/Input', | ||
component: Input, | ||
argTypes, | ||
parameters: { | ||
docs: { | ||
page: mdx, | ||
}, | ||
}, | ||
} |