diff --git a/src/atoms/checkbox/__tests__/__snapshots__/checkbox.test.tsx.snap b/src/atoms/checkbox/__tests__/__snapshots__/checkbox.test.tsx.snap index c0394827..240e702e 100644 --- a/src/atoms/checkbox/__tests__/__snapshots__/checkbox.test.tsx.snap +++ b/src/atoms/checkbox/__tests__/__snapshots__/checkbox.test.tsx.snap @@ -35,38 +35,6 @@ exports[`Checkbox renders 1`] = ` cursor: pointer; } -.c2:checked:not(:disabled)[aria-checked='true'] ~ span { - background-color: #35E0AD; - border-color: #2AB38A; -} - -.c2:checked:not(:disabled)[aria-checked='true'] ~ span:after { - display: block; -} - -.c2:checked:disabled[aria-checked='true'] ~ span { - border-color: transparent; - background-color: #E3E3E8; - color: #ABACBA; -} - -.c2:checked:disabled[aria-checked='true'] ~ span:after { - display: block; -} - -.c2:not(:checked):disabled ~ span { - border-color: #E3E3E8; - background-color: #ffffff; -} - -.c2:hover:not(:disabled) { - border-color: #4329A6; -} - -.c2:hover:not(:disabled):checked ~ span { - border-color: #2AB38A; -} - .c3 { position: absolute; top: 0; diff --git a/src/atoms/checkbox/index.tsx b/src/atoms/checkbox/index.tsx index 9c65f2a7..7885a538 100644 --- a/src/atoms/checkbox/index.tsx +++ b/src/atoms/checkbox/index.tsx @@ -6,7 +6,7 @@ import { Checkmark, } from './styles'; -interface Props { +export interface CheckboxProps { value: string; label?: string | React.ReactNode; checked?: boolean | undefined; @@ -30,7 +30,7 @@ const Checkbox = ({ style, dataTestId, required = false, -}: Props) => { +}: CheckboxProps) => { const checkedRef = useRef(checked); const [isChecked, setIsChecked] = useState(checked); diff --git a/stories/atoms/checkbox.stories.tsx b/src/atoms/checkbox/stories/checkbox.stories.tsx similarity index 78% rename from stories/atoms/checkbox.stories.tsx rename to src/atoms/checkbox/stories/checkbox.stories.tsx index 8ae60001..182cff85 100644 --- a/stories/atoms/checkbox.stories.tsx +++ b/src/atoms/checkbox/stories/checkbox.stories.tsx @@ -1,12 +1,14 @@ import React from 'react'; -import { Checkbox } from '../../src'; +import Checkbox, { CheckboxProps } from '..'; export default { title: 'Components/Atoms/Checkbox', component: Checkbox, }; -export const CheckboxSimpleComponent = args => ; +export const CheckboxSimpleComponent = (args: CheckboxProps) => ( + +); CheckboxSimpleComponent.storyName = 'Simple'; CheckboxSimpleComponent.args = { @@ -19,7 +21,7 @@ CheckboxSimpleComponent.args = { onChange: () => {}, }; -export const CheckboxNodeComponent = args => ( +export const CheckboxNodeComponent = (args: CheckboxProps) => ( ` left: 0; opacity: 0; cursor: pointer; - - &:checked:not(:disabled)[aria-checked='true'] ~ span { - background-color: ${props => - props.error ? field.errorBackgroundColor : field.successBackgroundColor}; - border-color: ${props => - props.error ? field.errorBorderColor : field.successBorderColor}; - - &:after { - display: block; - } - } - - &:checked:disabled[aria-checked='true'] ~ span { - border-color: transparent; - background-color: ${field.disabledBackgroundColor}; - color: ${field.disabledColor}; - - &:after { - display: block; - } - } - - &:not(:checked):disabled ~ span { - border-color: ${field.disabledBackgroundColor}; - background-color: ${field.backgroundColor}; - } - - &:hover:not(:disabled) { - border-color: ${props => - props.error ? field.errorBorderColor : field.activeBorderColor}; - - &:checked ~ span { - border-color: ${props => - props.error ? field.errorBorderColor : field.successBorderColor}; - } - } `; export const Checkmark = styled.span` diff --git a/src/atoms/error-field/index.tsx b/src/atoms/error-field/index.tsx index 45ec9335..f8d956a7 100644 --- a/src/atoms/error-field/index.tsx +++ b/src/atoms/error-field/index.tsx @@ -2,7 +2,7 @@ import React, { CSSProperties } from 'react'; import * as Styles from './styles'; import { ErrorFieldColor } from './types'; -interface ErrorFieldProps { +export interface ErrorFieldProps { color?: ErrorFieldColor; error: string; className?: string; diff --git a/stories/atoms/error-field.stories.tsx b/src/atoms/error-field/stories/error-field.stories.tsx similarity index 68% rename from stories/atoms/error-field.stories.tsx rename to src/atoms/error-field/stories/error-field.stories.tsx index a2898bc2..2cea74f2 100644 --- a/stories/atoms/error-field.stories.tsx +++ b/src/atoms/error-field/stories/error-field.stories.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ErrorField } from '../../src'; +import ErrorField, { ErrorFieldProps } from '..'; export default { title: 'Components/Atoms/ErrorField', @@ -14,7 +14,9 @@ export default { }, }; -export const ErrorComponent = args => ; +export const ErrorComponent = (args: ErrorFieldProps) => ( + +); ErrorComponent.storyName = 'Error'; ErrorComponent.args = { @@ -22,7 +24,9 @@ ErrorComponent.args = { color: 'red', }; -export const SuccessComponent = args => ; +export const SuccessComponent = (args: ErrorFieldProps) => ( + +); SuccessComponent.storyName = 'Success'; SuccessComponent.args = { diff --git a/src/atoms/spinner/index.tsx b/src/atoms/spinner/index.tsx index d9907a55..5d47c085 100644 --- a/src/atoms/spinner/index.tsx +++ b/src/atoms/spinner/index.tsx @@ -2,7 +2,7 @@ import React, { CSSProperties } from 'react'; import { colors } from '../../ions/variables'; import * as Styles from './styles'; -interface SpinnerProps { +export interface SpinnerProps { fill?: string; size?: string; className?: string; diff --git a/stories/atoms/spinner.stories.tsx b/src/atoms/spinner/stories/spinner.stories.tsx similarity index 68% rename from stories/atoms/spinner.stories.tsx rename to src/atoms/spinner/stories/spinner.stories.tsx index da618e9a..9c78aa97 100644 --- a/stories/atoms/spinner.stories.tsx +++ b/src/atoms/spinner/stories/spinner.stories.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Spinner } from '../../src'; +import Spinner, { SpinnerProps } from '..'; export default { title: 'Components/Atoms/Spinner', @@ -9,7 +9,7 @@ export default { }, }; -export const SpinnerComponent = args => ; +export const SpinnerComponent = (args: SpinnerProps) => ; SpinnerComponent.storyName = 'Spinner'; diff --git a/src/atoms/text-field/index.tsx b/src/atoms/text-field/index.tsx index c7574383..582f0575 100644 --- a/src/atoms/text-field/index.tsx +++ b/src/atoms/text-field/index.tsx @@ -3,7 +3,7 @@ import { ErrorField } from '../..'; import * as Styles from './styles'; import { TextFieldType } from './types'; -interface TextFieldProps { +export interface TextFieldProps { type?: TextFieldType; error?: string; icon?: string; diff --git a/stories/atoms/text-field.stories.tsx b/src/atoms/text-field/stories/text-field.stories.tsx similarity index 71% rename from stories/atoms/text-field.stories.tsx rename to src/atoms/text-field/stories/text-field.stories.tsx index c89869b0..049bb544 100644 --- a/stories/atoms/text-field.stories.tsx +++ b/src/atoms/text-field/stories/text-field.stories.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { TextField } from '../../src'; -import icons from '../../src/ions/icons'; +import TextField, { TextFieldProps } from '..'; +import icons from '../../../ions/icons'; export default { title: 'Components/Atoms/TextField', @@ -21,7 +21,7 @@ export default { }, }; -export const TextComponent = args => ; +export const TextComponent = (args: TextFieldProps) => ; TextComponent.storyName = 'Text'; TextComponent.args = { @@ -34,7 +34,9 @@ TextComponent.args = { required: false, }; -export const TextDefaultComponent = args => ; +export const TextDefaultComponent = (args: TextFieldProps) => ( + +); TextDefaultComponent.storyName = 'Default Value'; TextDefaultComponent.args = { @@ -46,7 +48,9 @@ TextDefaultComponent.args = { disabled: false, }; -export const DisabledComponent = args => ; +export const DisabledComponent = (args: TextFieldProps) => ( + +); DisabledComponent.storyName = 'Disabled'; DisabledComponent.args = { @@ -58,7 +62,9 @@ DisabledComponent.args = { disabled: true, }; -export const TextFullBorderComponent = args => ; +export const TextFullBorderComponent = (args: TextFieldProps) => ( + +); TextFullBorderComponent.storyName = 'Full Border'; TextFullBorderComponent.args = { @@ -69,7 +75,9 @@ TextFullBorderComponent.args = { disabled: false, }; -export const TextIconComponent = args => ; +export const TextIconComponent = (args: TextFieldProps) => ( + +); TextIconComponent.storyName = 'W/ Icon'; TextIconComponent.args = { @@ -81,7 +89,7 @@ TextIconComponent.args = { disabled: false, }; -export const UrlComponent = args => ; +export const UrlComponent = (args: TextFieldProps) => ; UrlComponent.storyName = 'URL'; UrlComponent.args = { @@ -92,7 +100,9 @@ UrlComponent.args = { disabled: false, }; -export const PasswordComponent = args => ; +export const PasswordComponent = (args: TextFieldProps) => ( + +); PasswordComponent.storyName = 'Password'; PasswordComponent.args = { @@ -103,7 +113,7 @@ PasswordComponent.args = { disabled: false, }; -export const DateComponent = args => ; +export const DateComponent = (args: TextFieldProps) => ; DateComponent.storyName = 'Date'; DateComponent.args = { @@ -113,7 +123,7 @@ DateComponent.args = { disabled: false, }; -export const TimeComponent = args => ; +export const TimeComponent = (args: TextFieldProps) => ; TimeComponent.storyName = 'Time'; TimeComponent.args = { @@ -123,7 +133,9 @@ TimeComponent.args = { disabled: false, }; -export const NumberComponent = args => ; +export const NumberComponent = (args: TextFieldProps) => ( + +); NumberComponent.storyName = 'Number'; NumberComponent.args = { @@ -136,7 +148,9 @@ NumberComponent.args = { disabled: false, }; -export const TextErrorComponent = args => ; +export const TextErrorComponent = (args: TextFieldProps) => ( + +); TextErrorComponent.storyName = 'Error'; TextErrorComponent.args = { diff --git a/src/molecules/actions-menu/index.tsx b/src/molecules/actions-menu/index.tsx index e8ceb8a2..8bfff0b3 100644 --- a/src/molecules/actions-menu/index.tsx +++ b/src/molecules/actions-menu/index.tsx @@ -4,14 +4,14 @@ import { Button } from '../..'; import { ActionMenu } from './types'; import * as Styles from './styles'; -interface ActionsMenuListInterface { +export interface ActionsMenuListInterface { actions: ActionMenu[]; data?: any; rowIndex?: number; handleOptionClick?: () => void; } -interface ActionsMenuInterface { +export interface ActionsMenuInterface { className?: string; ariaLabel?: string; actions: ActionMenu[]; diff --git a/stories/molecules/actions-menu.stories.tsx b/src/molecules/actions-menu/stories/actions-menu.stories.tsx similarity index 55% rename from stories/molecules/actions-menu.stories.tsx rename to src/molecules/actions-menu/stories/actions-menu.stories.tsx index c0cea9fe..1ad1e376 100644 --- a/stories/molecules/actions-menu.stories.tsx +++ b/src/molecules/actions-menu/stories/actions-menu.stories.tsx @@ -1,5 +1,8 @@ import React from 'react'; -import { ActionsMenu } from '../../src'; +import ActionsMenu, { + ActionsMenuInterface, + ActionsMenuListInterface, +} from '..'; export default { title: 'Components/Molecules/ActionsMenu', @@ -7,7 +10,17 @@ export default { argTypes: {}, }; -export const ActionsMenuOpenComponent = args => ; +type MyActionsMenuListInterface = ActionsMenuListInterface<{ + id: string; + type: string; + value: string; + url: string | null; + action: () => void; +}>; + +export const ActionsMenuOpenComponent = ( + args: ActionsMenuInterface +) => ; const actions = [ { @@ -40,7 +53,15 @@ ActionsMenuOpenComponent.args = { startsOpen: true, }; -export const ActionsMenuClosedComponent = args => ; +export const ActionsMenuClosedComponent = ( + args: ActionsMenuInterface +) => ; + +ActionsMenuClosedComponent.storyName = 'Closed'; +ActionsMenuClosedComponent.args = { + ...ActionsMenuOpenComponent.args, + startsOpen: false, +}; ActionsMenuClosedComponent.storyName = 'Closed'; ActionsMenuClosedComponent.args = { diff --git a/src/molecules/checkbox-group/__tests__/__snapshots__/checkbox-group.test.tsx.snap b/src/molecules/checkbox-group/__tests__/__snapshots__/checkbox-group.test.tsx.snap index 959c779b..5d773f9f 100644 --- a/src/molecules/checkbox-group/__tests__/__snapshots__/checkbox-group.test.tsx.snap +++ b/src/molecules/checkbox-group/__tests__/__snapshots__/checkbox-group.test.tsx.snap @@ -35,38 +35,6 @@ exports[`CheckboxGroup renders 1`] = ` cursor: pointer; } -.c3:checked:not(:disabled)[aria-checked='true'] ~ span { - background-color: #35E0AD; - border-color: #2AB38A; -} - -.c3:checked:not(:disabled)[aria-checked='true'] ~ span:after { - display: block; -} - -.c3:checked:disabled[aria-checked='true'] ~ span { - border-color: transparent; - background-color: #E3E3E8; - color: #ABACBA; -} - -.c3:checked:disabled[aria-checked='true'] ~ span:after { - display: block; -} - -.c3:not(:checked):disabled ~ span { - border-color: #E3E3E8; - background-color: #ffffff; -} - -.c3:hover:not(:disabled) { - border-color: #4329A6; -} - -.c3:hover:not(:disabled):checked ~ span { - border-color: #2AB38A; -} - .c4 { position: absolute; top: 0; diff --git a/src/molecules/field-with-button/__tests__/field-with-button.test.tsx b/src/molecules/field-with-button/__tests__/field-with-button.test.tsx index ff646c44..da6699f8 100644 --- a/src/molecules/field-with-button/__tests__/field-with-button.test.tsx +++ b/src/molecules/field-with-button/__tests__/field-with-button.test.tsx @@ -15,11 +15,22 @@ describe('FieldWidthButton', () => { it('has correct value', () => { const textValue = 'this is my text'; - render( + + // It renders with an initial value + const { rerender } = render( ); const foundInput = screen.getByDisplayValue(textValue); expect(foundInput).toHaveValue(textValue); + + // The previous value is replaced by changing the prop `value` + const secondTextValue = 'custom text after render'; + rerender( + + ); + expect(screen.getByDisplayValue(secondTextValue)).toHaveValue( + secondTextValue + ); }); it('calls action callback', async () => { diff --git a/src/molecules/field-with-button/index.tsx b/src/molecules/field-with-button/index.tsx index b02d32a5..8b34df36 100644 --- a/src/molecules/field-with-button/index.tsx +++ b/src/molecules/field-with-button/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import Label from '../../atoms/label'; import TextField from '../../atoms/text-field'; import { TextFieldType } from '../../atoms/text-field/types'; @@ -21,26 +21,24 @@ export interface FieldWidthButtonProps { clearFieldAfterSubmit?: boolean; } -const FieldWidthButton = (props: FieldWidthButtonProps) => { - const { - label, - type = 'text', - name, - placeholder, - value, - onChange, - dataTestId, - buttonIcon, - buttonValue, - buttonAction, - buttonDisabled, - disabled = true, - clearFieldAfterSubmit = false, - } = props; - +const FieldWidthButton = ({ + label, + type = 'text', + name, + placeholder, + value, + onChange, + dataTestId, + buttonIcon, + buttonValue, + buttonAction, + buttonDisabled, + disabled = true, + clearFieldAfterSubmit = false, +}: FieldWidthButtonProps) => { const [loading, setLoading] = useState(false); const [fieldValue, setFieldValue] = useState( - value ?? null + value ?? '' ); const handleOnClickAction = async () => { @@ -55,6 +53,11 @@ const FieldWidthButton = (props: FieldWidthButtonProps) => { clearFieldAfterSubmit && setFieldValue(''); }; + useEffect(() => { + if (!value) return; + setFieldValue(value); + }, [value]); + return ( {label &&