From a629568d7b896aecf6bbf3be0adbd175424c3b96 Mon Sep 17 00:00:00 2001 From: Carlos Cortizas <97907068+CarlosCortizasCT@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:29:09 +0100 Subject: [PATCH] Migrate components default props usage (#3027) * refactor(design-system): migrate design system components * refactor(design-system): migrate vrt utility components * refactor(design-system): migrate calendar-utils components * refactor(design-system): migrate butons components * refactor(design-system): migrate collapsible components * refactor(design-system): migrate data table components * refactor(design-system): migrate spacings components * refactor(design-system): migrate input components * refactor(inputs): adjust missing parts * refactor: adjust the rest of the components * refactor: adjust default props on pending components * chore: remove files * chore: remove files --- .editorconfig | 2 +- design-system/src/theme-provider.tsx | 24 +++--- .../src/calendar-body/calendar-body.tsx | 36 +++++--- packages/components/avatar/src/avatar.tsx | 54 +++++++----- .../src/accessible-button.tsx | 32 ++++--- .../buttons/flat-button/src/flat-button.tsx | 73 +++++++++------- .../buttons/icon-button/src/icon-button.tsx | 67 ++++++++------- .../buttons/link-button/src/link-button.tsx | 34 ++++---- .../primary-button/src/primary-button.tsx | 54 ++++++------ .../secondary-button/src/secondary-button.tsx | 84 +++++++++++-------- .../src/secondary-icon-button.tsx | 55 +++++++----- packages/components/card/src/card.tsx | 39 +++++---- .../src/collapsible-motion.tsx | 15 ++-- .../src/collapsible-panel.tsx | 61 +++++++------- .../collapsible-panel/src/header-icon.tsx | 9 +- .../collapsible/src/collapsible.tsx | 14 ++-- .../column-settings-manager.tsx | 18 ++-- .../display-settings-manager.tsx | 19 ++--- .../settings-container/settings-container.tsx | 12 ++- packages/components/data-table/src/cell.tsx | 30 +++---- .../components/data-table/src/data-row.tsx | 44 +++++----- .../data-table/src/data-table.stories.tsx | 8 +- .../components/data-table/src/data-table.tsx | 78 ++++++++--------- .../components/data-table/src/header-cell.tsx | 27 +++--- .../dropdown-menu/src/dropdown-menu.tsx | 31 ++++--- .../field-label/src/field-label.tsx | 12 ++- .../password-field/src/password-field.tsx | 25 +++--- .../src/search-select-field.tsx | 18 ++-- packages/components/grid/src/grid.tsx | 10 +-- .../icons/src/custom-icon/custom-icon.tsx | 30 ++++--- .../icons/src/leading-icon/leading-icon.tsx | 23 +++-- .../src/async-creatable-select-input.tsx | 40 ++++----- .../src/async-select-input.tsx | 77 ++++++++--------- .../checkbox-input/src/checkbox-input.tsx | 43 +++++----- .../src/creatable-select-input.tsx | 36 ++++---- .../localized-input-toggle.tsx | 21 ++--- .../src/multiline-input/multiline-input.tsx | 20 +++-- .../src/localized-money-input.tsx | 19 +++-- .../src/localized-multiline-text-input.tsx | 26 +++--- .../src/translation-input.tsx | 15 ++-- .../src/localized-rich-text-input.tsx | 27 +++--- .../src/localized-text-input.tsx | 19 +++-- .../inputs/money-input/src/money-input.tsx | 50 ++++++----- .../src/multiline-text-input.tsx | 27 +++--- .../inputs/number-input/src/number-input.tsx | 17 ++-- .../password-input/src/password-input.tsx | 39 +++++---- .../inputs/radio-input/src/radio-group.tsx | 51 ++++++----- .../inputs/radio-input/src/radio-option.tsx | 14 ++-- .../src/rich-text-body/dropdown.tsx | 31 ++++--- .../src/rich-text-body/rich-text-body.tsx | 10 +-- .../src/search-select-input.tsx | 53 ++++++------ .../src/search-text-input.tsx | 22 +++-- .../inputs/select-input/src/select-input.tsx | 72 ++++++++-------- .../src/selectable-search-input.spec.tsx | 66 +++++++++------ .../src/selectable-search-input.tsx | 55 ++++++------ .../inputs/text-input/src/text-input.tsx | 17 ++-- .../inputs/time-input/src/time-input.tsx | 10 +-- .../toggle-input/src/toggle-input.spec.tsx | 3 +- .../toggle-input/src/toggle-input.styles.ts | 15 +++- .../inputs/toggle-input/src/toggle-input.tsx | 49 ++++++----- packages/components/link/src/link.tsx | 31 ++++--- .../loading-spinner/src/loading-spinner.tsx | 20 ++--- .../page-size-selector/page-size-selector.tsx | 23 ++--- .../components/pagination/src/pagination.tsx | 22 +++-- .../primary-action-dropdown/src/option.tsx | 9 +- .../src/primary-action-dropdown.tsx | 6 +- .../progress-bar/src/progress-bar.styles.tsx | 15 ++-- .../progress-bar/src/progress-bar.tsx | 52 ++++++------ .../spacings/spacings-inline/src/inline.tsx | 37 ++++---- .../src/inset-squish.tsx | 25 +++--- .../spacings/spacings-inset/src/inset.tsx | 25 +++--- .../spacings/spacings-stack/src/stack.tsx | 28 +++++-- packages/components/stamp/src/stamp.tsx | 33 ++++---- packages/components/tag/src/tag-body.tsx | 26 +++--- packages/components/tag/src/tag.styles.ts | 6 +- packages/components/tag/src/tag.tsx | 43 +++++----- packages/components/tooltip/src/tooltip.tsx | 38 ++++----- test/percy/spec.jsx | 15 ++-- 78 files changed, 1264 insertions(+), 1172 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3ce9044524..409a2dd74a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,4 +8,4 @@ end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true -trim_trailing_whitespace = true +trim_trailing_whitespace = true \ No newline at end of file diff --git a/design-system/src/theme-provider.tsx b/design-system/src/theme-provider.tsx index 7b1b608584..1a3fb96261 100644 --- a/design-system/src/theme-provider.tsx +++ b/design-system/src/theme-provider.tsx @@ -65,13 +65,17 @@ const applyTheme = ({ }; type ThemeProviderProps = { - parentSelector: typeof defaultParentSelector; - theme: string; + parentSelector?: typeof defaultParentSelector; + theme?: string; themeOverrides?: Record; }; -const ThemeProvider = (props: ThemeProviderProps) => { - const parentSelectorRef = useRef(props.parentSelector); +const ThemeProvider = ({ + parentSelector = defaultParentSelector, + theme = 'default', + ...props +}: ThemeProviderProps) => { + const parentSelectorRef = useRef(parentSelector); const themeNameRef = useRef(); const themeOverridesRef = useRef>(); @@ -80,26 +84,22 @@ const ThemeProvider = (props: ThemeProviderProps) => { // provided include a new object with the same theme overrides // (eg: users providing an inline object as prop to the ThemeProvider) if ( - themeNameRef.current !== props.theme || + themeNameRef.current !== theme || !isEqual(themeOverridesRef.current, props.themeOverrides) ) { - themeNameRef.current = props.theme; + themeNameRef.current = theme; themeOverridesRef.current = props.themeOverrides; applyTheme({ - newTheme: props.theme, + newTheme: theme, parentSelector: parentSelectorRef.current, themeOverrides: props.themeOverrides, }); } - }, [props.theme, props.themeOverrides]); + }, [theme, props.themeOverrides]); return null; }; -ThemeProvider.defaultProps = { - parentSelector: defaultParentSelector, - theme: 'default', -}; type TUseThemeResult = { theme: ThemeName; diff --git a/packages/calendar-utils/src/calendar-body/calendar-body.tsx b/packages/calendar-utils/src/calendar-body/calendar-body.tsx index 47592f159f..81807ed55f 100644 --- a/packages/calendar-utils/src/calendar-body/calendar-body.tsx +++ b/packages/calendar-utils/src/calendar-body/calendar-body.tsx @@ -79,11 +79,10 @@ export type TCalendarBody = { theme?: Theme; }; -const defaultProps: Pick = { - isClearable: true, -}; - -export const CalendarBody = (props: TCalendarBody) => { +export const CalendarBody = ({ + isClearable = true, + ...props +}: TCalendarBody) => { const [isFocused, toggleIsFocused] = useToggleState(false); const onInputFocus = props.inputProps?.onFocus; @@ -130,18 +129,29 @@ export const CalendarBody = (props: TCalendarBody) => { return ( -
+
- {!disabledOrReadOnly && props.hasSelection && props.isClearable && ( + {!disabledOrReadOnly && props.hasSelection && isClearable && ( { )}