From cdb17d7f6b4f694a910214927a423b902fd32753 Mon Sep 17 00:00:00 2001 From: Karine Brandelli Date: Thu, 23 May 2024 15:33:34 -0300 Subject: [PATCH 01/27] fix: adjust Actions component --- src/experimental/actions/actions.stories.tsx | 109 +++++++++++++++++-- src/experimental/actions/index.tsx | 35 ++---- src/experimental/actions/styles.ts | 16 +++ src/experimental/index.ts | 2 +- 4 files changed, 129 insertions(+), 33 deletions(-) create mode 100644 src/experimental/actions/styles.ts diff --git a/src/experimental/actions/actions.stories.tsx b/src/experimental/actions/actions.stories.tsx index b747fb2f..5dad7c95 100644 --- a/src/experimental/actions/actions.stories.tsx +++ b/src/experimental/actions/actions.stories.tsx @@ -1,14 +1,107 @@ import React from 'react' -import type { Meta, StoryFn } from '@storybook/react' -import { Actions } from '.' +import type { Meta, StoryObj } from '@storybook/react' +import Actions from '.' -export default { +const meta: Meta = { title: 'Experimental/Actions', - component: Actions -} as Meta + component: Actions, + argTypes: { + names: { + table: { + disable: true + } + }, + readonly: { + table: { + disable: true + } + }, -const Template: StoryFn = args => { - return + prefix: { + table: { + disable: true + } + }, + align: { + options: ['flex-end', 'flex-start', 'center'], + control: { type: 'radio' }, + description: + "The buttons position. Must be `'flex-end' | 'flex-start' | 'center'`" + }, + buttons: { + control: false, + description: + "The buttons inner text. Must be `Array<'confirm' | 'cancel'>`" + + "If not informed, it will be used the default 'Cancelar' and 'Confirmar'" + }, + labels: { + cancel: { + control: 'text' + }, + confirm: { + control: 'text' + }, + description: + 'The buttons inner label. Must be and object with the cancel and confirm keys.' + }, + padding: { + control: 'text', + description: 'The buttons padding' + }, + margin: { + control: 'text', + description: 'The buttons margin.' + }, + actionButtonColor: { + options: ['inherit', 'primary', 'secondary', 'default', undefined], + control: { type: 'radio' }, + description: + 'The "Confirmar" button color.' + + 'Must be `"inherit" | "primary" | "secondary" | "default" | undefined`' + + 'If not set, the default is "secondary"' + }, + disabled: { + control: 'boolean', + description: 'If `true`, the buttons are disabled.' + }, + disabledCancel: { + control: 'boolean', + description: 'If `true`, the Cancel button is disabled.' + }, + disabledConfirm: { + control: 'boolean', + description: 'If `true`, the Confirm button is disabled.' + }, + onCancel: { + control: false, + description: 'The onCancel function, must be `() => void | boolean`' + }, + onConfirm: { + control: false, + description: 'The onConfirm function, must be `() => void`' + } + } } -export const Default = Template.bind({}) +export default meta + +type Story = StoryObj + +export const actions: Story = { + render: ({ ...args }) => { + return + }, + args: { + align: 'flex-end', + margin: '', + padding: '', + buttons: ['cancel', 'confirm'], + labels: { cancel: 'Cancelar', confirm: 'Confirmar' }, + actionButtonColor: 'primary', + disabled: false, + disabledCancel: false, + disabledConfirm: false, + onCancel: () => alert('Cancelar'), + onConfirm: () => alert('Confirmar') + } +} diff --git a/src/experimental/actions/index.tsx b/src/experimental/actions/index.tsx index be70b954..fdcf51ec 100644 --- a/src/experimental/actions/index.tsx +++ b/src/experimental/actions/index.tsx @@ -1,13 +1,15 @@ import React from 'react' -import { default as styled } from 'styled-components' import type { ButtonProps } from '@material-ui/core' import { Button } from '@/index' +import { Wrapper } from './styles' export interface IProps { padding?: number | string margin?: number | string align?: 'flex-end' | 'flex-start' | 'center' - disabled?: boolean + prefix?: string + buttons?: Array<'confirm' | 'cancel'> + actionButtonColor?: ButtonProps['color'] names?: { cancel: string confirm: string @@ -17,29 +19,14 @@ export interface IProps { confirm: string } readonly?: boolean - prefix?: string - buttons?: Array<'confirm' | 'cancel'> - actionButtonColor?: ButtonProps['color'] + disabled?: boolean + disabledCancel?: boolean + disabledConfirm?: boolean onCancel?(): void | boolean onConfirm(): void } -interface IWrapper { - padding?: IProps['padding'] - margin?: IProps['margin'] - align: IProps['align'] -} - -export const Wrapper = styled.div` - grid-area: actions; - display: flex; - flex: 1; - justify-content: flex-end; - padding: ${props => props.padding}; - margin: ${props => props.margin}; -` - -export const Actions = (props: IProps) => { +const Actions = (props: IProps) => { const showButton = !props.readonly && (!props.buttons || props.buttons.includes('confirm')) @@ -51,7 +38,7 @@ export const Actions = (props: IProps) => { {(!props.buttons || props.buttons.includes('cancel')) && (