Skip to content

Commit

Permalink
fix(intl message types): update intl message types to use correct typ…
Browse files Browse the repository at this point in the history
…es from react-intl instead of custom props defined in components
  • Loading branch information
ByronDWall committed Jan 22, 2025
1 parent 02c89c7 commit b6abdf9
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useState, type ReactNode } from 'react';
import { warning } from '@commercetools-uikit/utils';
import { useIntl, type MessageDescriptor } from 'react-intl';
import { useIntl, type IntlFormatters } from 'react-intl';
import styled from '@emotion/styled';
import { ColumnsIcon } from '@commercetools-uikit/icons';
import Spacings from '@commercetools-uikit/spacings';
Expand Down Expand Up @@ -56,7 +56,7 @@ export const getDropdownOptions = ({
customSettings?: TCustomSettingsProps[];
columnManagerLabel?: string;
displaySettingsLabel?: string;
formatMessage: (message: MessageDescriptor) => string;
formatMessage: IntlFormatters<ReactNode>['formatMessage'];
}) => {
return [
...(areColumnSettingsEnabled !== undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { KeyboardEvent, MouseEvent, ReactElement, ReactNode } from 'react';
import { useIntl, type MessageDescriptor } from 'react-intl';
import { useIntl } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import styled from '@emotion/styled';
import AccessibleButton from '@commercetools-uikit/accessible-button';
import CollapsibleMotion from '@commercetools-uikit/collapsible-motion';
Expand All @@ -9,15 +10,11 @@ import Text from '@commercetools-uikit/text';
import { CloseIcon } from '@commercetools-uikit/icons';
import { designTokens } from '@commercetools-uikit/design-system';

export type TIntlMessage = MessageDescriptor & {
values?: Record<string, React.ReactNode>;
};
export type TIntlMessage = IntlMessage;

type TSettingsContainerProps = {
title?: TIntlMessage;
closeButtonLabel: MessageDescriptor & {
values?: Record<string, React.ReactNode>;
};
closeButtonLabel: IntlMessage;
onClose: (
event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
) => void;
Expand Down
3 changes: 1 addition & 2 deletions packages/components/data-table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ shouldIgnoreRowClick?: boolean;
*/
shouldIgnoreRowClick?: boolean;
}
```
````

### Signature `customColumns`

Expand Down Expand Up @@ -289,4 +289,3 @@ shouldIgnoreRowClick?: boolean;
```ts
(row: Row) => ReactNode;
```
````
4 changes: 2 additions & 2 deletions packages/components/filters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ npm --save install @commercetools-uikit/filters
Additionally install the peer dependencies (if not present)

```
yarn add react
yarn add react react-dom
```

```
npm --save install react
npm --save install react react-dom
```

## Usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css } from '@emotion/react';
import type { MessageDescriptor } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import { MouseEvent, KeyboardEvent, ReactElement } from 'react';
import { useIntl } from 'react-intl';
import FlatButton from '@commercetools-uikit/flat-button';
Expand All @@ -16,8 +16,8 @@ export type TLocalizedInputToggleProps = {
| boolean
) => void;
isDisabled?: boolean;
showMessage?: string | MessageDescriptor;
hideMessage?: string | MessageDescriptor;
showMessage?: string | IntlMessage;
hideMessage?: string | IntlMessage;
remainingLocalizations?: number;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
type ReactNode,
useCallback,
} from 'react';
import { FormattedMessage, type MessageDescriptor } from 'react-intl';
import { FormattedMessage } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import { css } from '@emotion/react';
import { useFieldId, useToggleState } from '@commercetools-uikit/hooks';
import {
Expand Down Expand Up @@ -150,14 +151,7 @@ export type TLocalizedTextInputProps = {
es: 'Algún valor',
}
*/
additionalInfo?: Record<
string,
| string
| ReactNode
| (MessageDescriptor & {
values: Record<string, ReactNode>;
})
>;
additionalInfo?: Record<string, string | ReactNode | IntlMessage>;
};

export type TLocalizedInputProps = {
Expand Down
8 changes: 3 additions & 5 deletions packages/components/label/src/label.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessageDescriptor } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';

import { Children, type ReactNode } from 'react';
import { FormattedMessage } from 'react-intl';
Expand Down Expand Up @@ -46,15 +46,13 @@ export type TLabelProps = {
// Indicates the tone to be applied to the label
tone?: 'primary' | 'inverted';
/**
* A `MessageDescriptor` rendered `children` to `Label`.
* An `IntlMessage` object rendered `children` to `Label`.
* <br />
* When a value is provided, `intlMessage` will be rendered instead of `children`
* <br />
* This is required when `children` is `undefined` and vice versa
*/
intlMessage?: MessageDescriptor & {
values?: Record<string, ReactNode>;
};
intlMessage?: IntlMessage;
/**
* Rendered as `children` to `Label`.
* <br />
Expand Down
6 changes: 2 additions & 4 deletions packages/components/link/src/link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LocationDescriptor } from 'history';
import type { MessageDescriptor } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import {
Children,
type ReactNode,
Expand All @@ -26,9 +26,7 @@ export type TLinkProps = {
* <br />
* Required if `children` is not provided.
*/
intlMessage?: MessageDescriptor & {
values?: Record<string, ReactNode>;
};
intlMessage?: IntlMessage;
/**
* A flag to indicate if the Link points to an external source.
* <bt />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { ReactNode } from 'react';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import Text from '@commercetools-uikit/text';

export type TIntlMessageDescriptor = {
id: string;
description?: string | object;
defaultMessage: string;
values?: Record<string, ReactNode>;
};
export type TIntlMessageDescriptor = IntlMessage;

export type TAdditionalInfoMessageProps = {
id?: string;
Expand All @@ -27,7 +23,7 @@ const AdditionalInfoMessage = (props: TAdditionalInfoMessageProps) => {

return (
<Text.Detail id={props.id} tone="tertiary">
{props.message}
{props.message as ReactNode}
</Text.Detail>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { ReactNode } from 'react';
import type { Props as IntlMessage } from 'react-intl/src/components/message';

import Text from '@commercetools-uikit/text';
import { filterDataAttributes } from '@commercetools-uikit/utils';

export type TIntlMessageDescriptor = {
id: string;
description?: string | object;
defaultMessage: string;
values?: Record<string, ReactNode>;
};
export type TIntlMessageDescriptor = IntlMessage;

export type TErrorMessageProps = {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { ReactNode } from 'react';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import Text from '@commercetools-uikit/text';

export type TIntlMessageDescriptor = {
id: string;
description?: string | object;
defaultMessage: string;
values?: Record<string, ReactNode>;
};
export type TIntlMessageDescriptor = IntlMessage;

export type TWarningMessageProps = {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { MessageDescriptor } from 'react-intl';

import type { Props as IntlMessage } from 'react-intl/src/components/message';
import {
Children,
type ReactNode,
Expand Down Expand Up @@ -30,9 +29,7 @@ export type TContentNotificationProps = {
* <br />
* Required if `children` is not provided.
*/
intlMessage?: MessageDescriptor & {
values?: Record<string, ReactNode>;
};
intlMessage?: IntlMessage;

/**
* When provided, a close button will be rendered and this callback will be
Expand Down
20 changes: 10 additions & 10 deletions packages/components/progress-bar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export default Example;

## Properties

| Props | Type | Required | Default | Description |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------- | :------: | -------------------------- | ---------------------------------------------------------------------------------------------------- |
| `progress` | `number` | | `0` | The percentage of the task completion to fill the bar. |
| `label` | `union`<br/>Possible values:<br/>`, string, ReactElement, (MessageDescriptor & { values?: Record<string, ReactNode> }), null` | | `null` | The text to display alongside the bar. |
| `labelPosition` | `union`<br/>Possible values:<br/>`'top' , 'bottom' , 'left' , 'right'` | | `'top'` | Location of the text in relation to the bar. |
| `labelWidth` | `union`<br/>Possible values:<br/>`, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `defaultStyles.labelWidth` | The scale of the width for the label, uses values available in the Constraints.Horizontal component. |
| `isInverted` | `boolean` | | `false` | Specifies the use of light colors(default) or dark colors. |
| `isAnimated` | `boolean` | | `true` | Specifies whether the inner bar should have the styles animated. |
| `height` | `union`<br/>Possible values:<br/>`'10' , '20'` | | `defaultStyles.height` | The scale of the height for the bar, also affects the styles of the label. |
| `barWidth` | `union`<br/>Possible values:<br/>`4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 'scale'` | | `6` | The scale of the width for the label, uses values available in the Constraints.Horizontal component. |
| Props | Type | Required | Default | Description |
| --------------- | ----------------------------------------------------------------------------------------------------- | :------: | -------------------------- | ---------------------------------------------------------------------------------------------------- |
| `progress` | `number` | | `0` | The percentage of the task completion to fill the bar. |
| `label` | `union`<br/>Possible values:<br/>`string , ReactElement , IntlMessage , null` | | `null` | The text to display alongside the bar. |
| `labelPosition` | `union`<br/>Possible values:<br/>`'top' , 'bottom' , 'left' , 'right'` | | `'top'` | Location of the text in relation to the bar. |
| `labelWidth` | `union`<br/>Possible values:<br/>`, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `defaultStyles.labelWidth` | The scale of the width for the label, uses values available in the Constraints.Horizontal component. |
| `isInverted` | `boolean` | | `false` | Specifies the use of light colors(default) or dark colors. |
| `isAnimated` | `boolean` | | `true` | Specifies whether the inner bar should have the styles animated. |
| `height` | `union`<br/>Possible values:<br/>`'10' , '20'` | | `defaultStyles.height` | The scale of the height for the bar, also affects the styles of the label. |
| `barWidth` | `union`<br/>Possible values:<br/>`4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 'scale'` | | `6` | The scale of the width for the label, uses values available in the Constraints.Horizontal component. |
11 changes: 4 additions & 7 deletions packages/components/progress-bar/src/progress-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactElement, ReactNode } from 'react';
import { FormattedMessage, type MessageDescriptor } from 'react-intl';
import { FormattedMessage } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';
import { filterAriaAttributes } from '@commercetools-uikit/utils';
import Constraints from '@commercetools-uikit/constraints';
import SpacingsInline from '@commercetools-uikit/spacings-inline';
Expand All @@ -21,11 +22,7 @@ export type TProgressBarProps = {
/**
* The text to display alongside the bar.
*/
label?:
| string
| ReactElement
| (MessageDescriptor & { values?: Record<string, ReactNode> })
| null;
label?: string | ReactElement | IntlMessage | null;
/**
* Location of the text in relation to the bar.
*/
Expand Down Expand Up @@ -80,7 +77,7 @@ const ProgressBarLabel = (
as: props.height !== '10' ? 'span' : undefined,
fontWegith: props.height !== '10' ? 'medium' : undefined,
children: props.label.hasOwnProperty('defaultMessage') ? (
<FormattedMessage {...(props.label as MessageDescriptor)} />
<FormattedMessage {...(props.label as IntlMessage)} />
) : (
(props.label as ReactNode)
),
Expand Down
6 changes: 2 additions & 4 deletions packages/components/text/src/text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MessageDescriptor } from 'react-intl';
import type { Props as IntlMessage } from 'react-intl/src/components/message';

import { Children, ReactNode } from 'react';
import { FormattedMessage } from 'react-intl';
Expand Down Expand Up @@ -26,9 +26,7 @@ export type TFontWeight = 'regular' | 'medium' | 'bold';

export type TBasicTextProps = {
id?: string;
intlMessage?: MessageDescriptor & {
values?: Record<string, React.ReactNode>;
};
intlMessage?: IntlMessage;
children?: ReactNode;
};

Expand Down

0 comments on commit b6abdf9

Please sign in to comment.