Skip to content

Commit

Permalink
Renamed components and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz committed Sep 20, 2023
1 parent 913a20e commit aeb715d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,8 +13,8 @@ export default {
export const Eksempel: StoryFn<typeof LegacyFieldSet> = (args) => (
<LegacyFieldSet {...args}>
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
<TextField label='Navn' />
<TextField
<LegacyTextField label='Navn' />
<LegacyTextField
type='date'
label='Fødselsdato'
/>
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/legacy/TextField/TextField.mdx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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';

<TextField {...props} />;
<LegacyTextField {...props} />;
```

## Props
Expand Down
Original file line number Diff line number Diff line change
@@ -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<typeof TextField>;
type Story = StoryObj<typeof LegacyTextField>;

const meta: Meta<typeof TextField> = {
title: 'Altinn/TextField',
component: TextField,
const meta: Meta<typeof LegacyTextField> = {
title: 'Avviklet/LegacyTextField',
component: LegacyTextField,
};

export default meta;

const createTemplate = (name: string, args?: TextFieldProps): Story => ({
render: (args) => <TextField {...args} />,
const createTemplate = (name: string, args?: LegacyTextFieldProps): Story => ({
render: (args) => <LegacyTextField {...args} />,
args,
name,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -172,7 +172,7 @@ describe('TextField', () => {
expect(screen.getByDisplayValue('$1 234')).toBeInTheDocument();
expect(onChange).not.toHaveBeenCalled();
rerender(
<TextField
<LegacyTextField
onChange={onChange}
value='12345'
formatting={{ number: { prefix: '$', thousandSeparator: ' ' } }}
Expand Down Expand Up @@ -301,11 +301,11 @@ describe('TextField', () => {
});
});

const render = (props: Partial<TextFieldProps> = {}) => {
const render = (props: Partial<LegacyTextFieldProps> = {}) => {
const allProps = {
onChange: jest.fn(),
...props,
} as TextFieldProps;
} as LegacyTextFieldProps;

return renderRtl(<TextField {...allProps} />);
return renderRtl(<LegacyTextField {...allProps} />);
};
13 changes: 8 additions & 5 deletions packages/react/src/components/legacy/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -65,7 +65,7 @@ export type TextFieldProps = {
'readOnly' | 'value' | 'defaultValue' | 'type'
>; // Todo: We should extend the props of <input> 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;
};
Expand All @@ -91,7 +91,10 @@ const replaceTargetValueWithUnformattedValue = ({
},
};
};
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
export const LegacyTextField = forwardRef<
HTMLInputElement,
LegacyTextFieldProps
>(
(
{
id,
Expand All @@ -107,7 +110,7 @@ export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
characterLimit,
'aria-describedby': ariaDescribedBy,
...rest
}: TextFieldProps,
}: LegacyTextFieldProps,
ref: ForwardedRef<HTMLInputElement>,
) => {
const [currentValue, setCurrentValue] = useState<string>(
Expand Down
7 changes: 5 additions & 2 deletions packages/react/src/components/legacy/TextField/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { TextField } from './TextField';
export type { TextFieldProps, TextFieldFormatting } from './TextField';
export { LegacyTextField } from './TextField';
export type {
LegacyTextFieldProps,
LegacyTextFieldFormatting,
} from './TextField';

0 comments on commit aeb715d

Please sign in to comment.