From aeb715d469baafc619dc2cdb2b8db35faceb069d Mon Sep 17 00:00:00 2001 From: Michael Marszalek Date: Wed, 20 Sep 2023 20:28:39 +0200 Subject: [PATCH] Renamed components and imports --- packages/react/src/components/index.ts | 2 +- .../legacy/LegacyFieldSet/FieldSet.stories.tsx | 6 +++--- .../components/legacy/TextField/TextField.mdx | 6 +++--- .../legacy/TextField/TextField.stories.tsx | 16 ++++++++-------- .../legacy/TextField/TextField.test.tsx | 12 ++++++------ .../components/legacy/TextField/TextField.tsx | 13 ++++++++----- .../src/components/legacy/TextField/index.ts | 7 +++++-- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/packages/react/src/components/index.ts b/packages/react/src/components/index.ts index 1fb31b188c..6bd6f05999 100644 --- a/packages/react/src/components/index.ts +++ b/packages/react/src/components/index.ts @@ -3,6 +3,7 @@ export * from './legacy/LegacyCheckbox'; export * from './legacy/LegacyCheckboxGroup'; export * from './legacy/LegacyRadioButton'; export * from './legacy/LegacyRadioGroup'; +export * from './legacy/TextField'; export * from './Button'; export * from './Tabs'; @@ -11,7 +12,6 @@ export * from './Popover'; export * from './Select'; export * from './Spinner'; export * from './TextArea'; -export * from './legacy/TextField'; export * from './Link'; export * from './List'; export * from './Table'; diff --git a/packages/react/src/components/legacy/LegacyFieldSet/FieldSet.stories.tsx b/packages/react/src/components/legacy/LegacyFieldSet/FieldSet.stories.tsx index 447273904f..c36d93aea8 100644 --- a/packages/react/src/components/legacy/LegacyFieldSet/FieldSet.stories.tsx +++ b/packages/react/src/components/legacy/LegacyFieldSet/FieldSet.stories.tsx @@ -1,7 +1,7 @@ import React from 'react'; import type { Meta, StoryFn } from '@storybook/react'; -import { TextField } from '../../TextField'; +import { LegacyTextField } from '../TextField'; import { LegacyFieldSet } from './FieldSet'; @@ -13,8 +13,8 @@ export default { export const Eksempel: StoryFn = (args) => (
- - + diff --git a/packages/react/src/components/legacy/TextField/TextField.mdx b/packages/react/src/components/legacy/TextField/TextField.mdx index 4f3c9630ce..735bea2d2b 100644 --- a/packages/react/src/components/legacy/TextField/TextField.mdx +++ b/packages/react/src/components/legacy/TextField/TextField.mdx @@ -1,6 +1,6 @@ import { Meta, Canvas, Story, Primary, Controls } from '@storybook/blocks'; import { TextField } from './'; -import { Information, TokensTable } from '../../../../../docs-components'; +import { Information, TokensTable } from '../../../../../../docs-components'; import { ArgsTable } from '@storybook/blocks'; import * as TextFieldStories from './TextField.stories'; @@ -15,9 +15,9 @@ import * as TextFieldStories from './TextField.stories'; ## Bruk ```tsx -import { TextField } from '@digdir/design-system-react'; +import { LegacyTextField } from '@digdir/design-system-react'; -; +; ``` ## Props diff --git a/packages/react/src/components/legacy/TextField/TextField.stories.tsx b/packages/react/src/components/legacy/TextField/TextField.stories.tsx index a9808d2f7c..4082a8074d 100644 --- a/packages/react/src/components/legacy/TextField/TextField.stories.tsx +++ b/packages/react/src/components/legacy/TextField/TextField.stories.tsx @@ -1,20 +1,20 @@ import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; -import type { TextFieldProps } from '.'; -import { TextField } from '.'; +import type { LegacyTextFieldProps } from '.'; +import { LegacyTextField } from '.'; -type Story = StoryObj; +type Story = StoryObj; -const meta: Meta = { - title: 'Altinn/TextField', - component: TextField, +const meta: Meta = { + title: 'Avviklet/LegacyTextField', + component: LegacyTextField, }; export default meta; -const createTemplate = (name: string, args?: TextFieldProps): Story => ({ - render: (args) => , +const createTemplate = (name: string, args?: LegacyTextFieldProps): Story => ({ + render: (args) => , args, name, }); diff --git a/packages/react/src/components/legacy/TextField/TextField.test.tsx b/packages/react/src/components/legacy/TextField/TextField.test.tsx index eeb39582f9..ebd477d023 100644 --- a/packages/react/src/components/legacy/TextField/TextField.test.tsx +++ b/packages/react/src/components/legacy/TextField/TextField.test.tsx @@ -2,8 +2,8 @@ import { render as renderRtl, screen } from '@testing-library/react'; import React from 'react'; import userEvent from '@testing-library/user-event'; -import type { TextFieldProps } from './TextField'; -import { TextField } from './TextField'; +import type { LegacyTextFieldProps } from './TextField'; +import { LegacyTextField } from './TextField'; const user = userEvent.setup(); @@ -172,7 +172,7 @@ describe('TextField', () => { expect(screen.getByDisplayValue('$1 234')).toBeInTheDocument(); expect(onChange).not.toHaveBeenCalled(); rerender( - { }); }); -const render = (props: Partial = {}) => { +const render = (props: Partial = {}) => { const allProps = { onChange: jest.fn(), ...props, - } as TextFieldProps; + } as LegacyTextFieldProps; - return renderRtl(); + return renderRtl(); }; diff --git a/packages/react/src/components/legacy/TextField/TextField.tsx b/packages/react/src/components/legacy/TextField/TextField.tsx index d95e2ebd23..10d6758f31 100644 --- a/packages/react/src/components/legacy/TextField/TextField.tsx +++ b/packages/react/src/components/legacy/TextField/TextField.tsx @@ -13,7 +13,7 @@ import { isNumericFormat, isPatternFormat } from '../../../utils'; import { InputWrapper } from '../../_InputWrapper'; import type { ReadOnlyVariant_, CharacterLimit } from '../../_InputWrapper'; -export type TextFieldProps = { +export type LegacyTextFieldProps = { /** * The characterLimit function calculates remaining characters. * Provide a `label` function that takes count as parameter and returns a message. @@ -25,7 +25,7 @@ export type TextFieldProps = { defaultValue?: string | number; /** The formatting options for the text field. */ - formatting?: TextFieldFormatting; + formatting?: LegacyTextFieldFormatting; /** Specifies whether the value of the text field is valid. */ isValid?: boolean; @@ -65,7 +65,7 @@ export type TextFieldProps = { 'readOnly' | 'value' | 'defaultValue' | 'type' >; // Todo: We should extend the props of here, but it's complex because of the number format implementation. We should move that out to a separate component first. -export type TextFieldFormatting = { +export type LegacyTextFieldFormatting = { align?: 'right' | 'center' | 'left'; number?: NumericFormatProps | PatternFormatProps; }; @@ -91,7 +91,10 @@ const replaceTargetValueWithUnformattedValue = ({ }, }; }; -export const TextField = forwardRef( +export const LegacyTextField = forwardRef< + HTMLInputElement, + LegacyTextFieldProps +>( ( { id, @@ -107,7 +110,7 @@ export const TextField = forwardRef( characterLimit, 'aria-describedby': ariaDescribedBy, ...rest - }: TextFieldProps, + }: LegacyTextFieldProps, ref: ForwardedRef, ) => { const [currentValue, setCurrentValue] = useState( diff --git a/packages/react/src/components/legacy/TextField/index.ts b/packages/react/src/components/legacy/TextField/index.ts index 03fca4ab6a..521d578804 100644 --- a/packages/react/src/components/legacy/TextField/index.ts +++ b/packages/react/src/components/legacy/TextField/index.ts @@ -1,2 +1,5 @@ -export { TextField } from './TextField'; -export type { TextFieldProps, TextFieldFormatting } from './TextField'; +export { LegacyTextField } from './TextField'; +export type { + LegacyTextFieldProps, + LegacyTextFieldFormatting, +} from './TextField';