diff --git a/.eslintrc.js b/.eslintrc.js index 51be281..90d11fc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -136,7 +136,7 @@ module.exports = { settings: { 'import/resolver': { node: { - extensions: ['js', 'jsx', '.ts', '.tsx'], + extensions: ['js', 'jsx', '.ts', '.tsx', '.css'], }, }, react: { diff --git a/.storybook/preview.js b/.storybook/preview.js index 48afd56..57a8213 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -1,3 +1,5 @@ +import '../src/shared/variables.css' + export const parameters = { actions: { argTypesRegex: "^on[A-Z].*" }, controls: { diff --git a/public/index.html b/public/index.html index 0176762..f455f3c 100644 --- a/public/index.html +++ b/public/index.html @@ -3,6 +3,9 @@ + + + void + size: ButtonSize + variant: ButtonVariant + className?: string + // Wait for theme palette + color?: string + htmlType?: ButtonHtmlType +} + +export const Button: FC = ({ + color, + disabled, + onClick, + variant, + size, + className, + children, + htmlType, + isLoading, +}) => { + const buttonStyles = classNames( + { + [styles.default]: true, + [styles.primary]: variant === ButtonVariant.primary, + [styles.outline]: variant === ButtonVariant.outline, + [styles.small]: size === ButtonSize.small, + [styles.withCustomColor]: !!color, + }, + className + ) + + return ( + + ) +} diff --git a/src/components/Button/Button.driver.tsx b/src/components/Button/Button.driver.tsx new file mode 100644 index 0000000..acd85e2 --- /dev/null +++ b/src/components/Button/Button.driver.tsx @@ -0,0 +1,100 @@ +import React, { ReactElement } from 'react' + +// eslint-disable-next-line import/no-extraneous-dependencies +import { fireEvent, render, screen } from '@testing-library/react' +import { + DataHooks as ButtonDataHooks, + ButtonSize, + ButtonVariant, + ButtonHtmlType, +} from 'components/Button/constants' + +import { Button, PropsType } from './Button.component' + +export type DriverType = { + given: { + children: (children: ReactElement) => DriverType + className: (className?: string) => DriverType + color: (color?: string) => DriverType + disabled: (disabled: boolean) => DriverType + htmlType: (htmlType?: ButtonHtmlType) => DriverType + isLoading: (isLoading: boolean) => DriverType + onClick: (onClick: () => null) => DriverType + size: (size: ButtonSize) => DriverType + variant: (variant: ButtonVariant) => DriverType + } + + then: { + clickButton: () => void + getButton: () => HTMLElement + isExistButton: () => boolean + isExistChildren: () => boolean + isLoadding: () => boolean + } + + when: { + created: () => DriverType + } +} + +export const createButtonDriver = (): DriverType => { + let props: PropsType + + const driver: DriverType = { + given: { + children: (children: ReactElement) => { + props = { ...props, children } + return driver + }, + color: (color?: string) => { + props = { ...props, color } + return driver + }, + disabled: (disabled: boolean) => { + props = { ...props, disabled } + return driver + }, + isLoading: (isLoading: boolean) => { + props = { ...props, isLoading } + return driver + }, + onClick: (onClick: () => null) => { + props = { ...props, onClick } + return driver + }, + size: (size: ButtonSize) => { + props = { ...props, size } + return driver + }, + className: (className?: string) => { + props = { ...props, className } + return driver + }, + variant: (variant: ButtonVariant) => { + props = { ...props, variant } + return driver + }, + htmlType: (htmlType?: ButtonHtmlType) => { + props = { ...props, htmlType } + return driver + }, + }, + when: { + created: () => { + // eslint-disable-next-line react/jsx-props-no-spreading + render( ) } + +export default Button diff --git a/src/stories/button.css b/src/stories/Button/button.css similarity index 100% rename from src/stories/button.css rename to src/stories/Button/button.css diff --git a/src/stories/Button/index.ts b/src/stories/Button/index.ts new file mode 100644 index 0000000..8486fd6 --- /dev/null +++ b/src/stories/Button/index.ts @@ -0,0 +1 @@ +export * from './Button' diff --git a/src/stories/Page.tsx b/src/stories/Page.tsx index bbc91bf..499e1ab 100644 --- a/src/stories/Page.tsx +++ b/src/stories/Page.tsx @@ -7,7 +7,7 @@ type User = { name: string } -export const Page: React.VFC = () => { +export const Page: React.FC = () => { const [user, setUser] = React.useState() return (