@transferwise/components 0.0.0-experimental-4873992 → 0.0.0-experimental-3cfaec8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/sentimentSurface/SentimentSurface.js +1 -1
- package/build/sentimentSurface/SentimentSurface.js.map +1 -1
- package/build/sentimentSurface/SentimentSurface.mjs +1 -1
- package/build/sentimentSurface/SentimentSurface.mjs.map +1 -1
- package/package.json +1 -1
- package/src/sentimentSurface/SentimentSurface.test.tsx +33 -0
- package/src/sentimentSurface/SentimentSurface.tsx +1 -1
|
@@ -29,7 +29,7 @@ const SentimentSurface = /*#__PURE__*/React.forwardRef(function SentimentSurface
|
|
|
29
29
|
const getThemeBrightness = () => {
|
|
30
30
|
const isForestGreen = theme.includes('forest-green');
|
|
31
31
|
const isPlatform = theme.includes('platform');
|
|
32
|
-
return
|
|
32
|
+
return isForestGreen || isDark && !isPlatform ? 'dark' : 'light';
|
|
33
33
|
};
|
|
34
34
|
const classNames = clsx.clsx(closestBrandTheme, BASE_CLASS, `wds-sentiment-${sentiment}-${getThemeBrightness()}-${emphasis}`, hasBaseStyles && `${BASE_CLASS}--hasBaseStyles`, className);
|
|
35
35
|
const sentimentProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentimentSurface.js","sources":["../../src/sentimentSurface/SentimentSurface.tsx"],"sourcesContent":["import { forwardRef, ElementType, ForwardedRef } from 'react';\nimport { clsx } from 'clsx';\n\nimport {\n SentimentSurfaceComponentProps,\n SentimentSurfaceComponent,\n} from './SentimentSurface.types';\nimport { useTheme } from '@wise/components-theming';\n\n/**\n * SentimentSurface is a polymorphic container component that exposes and, optionally, applies\n * contextual colour tokens as CSS custom properties, based on sentiment types (`negative`,\n * `warning`, `neutral`, `success`, `proposition`).\n *\n * @param {ElementType} [as='div'] - Optional prop to override the HTML element rendered.\n * @param {Sentiment} sentiment - Required prop to set the sentiment type (negative, warning, neutral, success, proposition).\n * @param {Emphasis} [emphasis='base'] - Optional prop to specify the emphasis level (base or elevated).\n * @param {boolean} [hasBaseStyles=true] - If true, sets the `background-color` and `color` on the container. Otherwise, only exposes the tokens as CSS custom properties without rendering.\n * @param {ReactNode} [children] - Content to render inside the surface.\n * @param {string} [className] - Additional CSS classes to apply.\n * @param {CSSProperties} [style] - Inline styles to apply.\n * @param {string} [id] - Unique identifier for the component.\n * @param {string} [data-testid] - A unique string that appears as data attribute `data-testid` in the rendered code.\n *\n * @component\n * @example\n * ```tsx\n * // Basic usage with negative sentiment\n * <SentimentSurface sentiment=\"negative\">\n * Your payment has failed\n * </SentimentSurface>\n * ```\n *\n * @see {@link SentimentSurface} for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/sentiment-surface--docs|Storybook Wise Design}\n */\n// @ts-expect-error - Generic forwardRef limitation. See: https://fettblog.eu/typescript-react-generic-forward-refs/\nconst SentimentSurface: SentimentSurfaceComponent = forwardRef(function SentimentSurface<\n T extends ElementType = 'div',\n>(\n {\n as,\n sentiment,\n emphasis = 'base',\n hasBaseStyles = true,\n style,\n className,\n children,\n id,\n 'data-testid': dataTestId,\n ...props\n }: SentimentSurfaceComponentProps<T>,\n ref: ForwardedRef<HTMLElement>,\n) {\n const Element = as ?? 'div';\n const BASE_CLASS = 'wds-sentiment-surface';\n const { className: closestBrandTheme, isScreenModeDark: isDark, theme } = useTheme();\n\n const getThemeBrightness = () => {\n const isForestGreen = theme.includes('forest-green');\n const isPlatform = theme.includes('platform');\n\n return
|
|
1
|
+
{"version":3,"file":"SentimentSurface.js","sources":["../../src/sentimentSurface/SentimentSurface.tsx"],"sourcesContent":["import { forwardRef, ElementType, ForwardedRef } from 'react';\nimport { clsx } from 'clsx';\n\nimport {\n SentimentSurfaceComponentProps,\n SentimentSurfaceComponent,\n} from './SentimentSurface.types';\nimport { useTheme } from '@wise/components-theming';\n\n/**\n * SentimentSurface is a polymorphic container component that exposes and, optionally, applies\n * contextual colour tokens as CSS custom properties, based on sentiment types (`negative`,\n * `warning`, `neutral`, `success`, `proposition`).\n *\n * @param {ElementType} [as='div'] - Optional prop to override the HTML element rendered.\n * @param {Sentiment} sentiment - Required prop to set the sentiment type (negative, warning, neutral, success, proposition).\n * @param {Emphasis} [emphasis='base'] - Optional prop to specify the emphasis level (base or elevated).\n * @param {boolean} [hasBaseStyles=true] - If true, sets the `background-color` and `color` on the container. Otherwise, only exposes the tokens as CSS custom properties without rendering.\n * @param {ReactNode} [children] - Content to render inside the surface.\n * @param {string} [className] - Additional CSS classes to apply.\n * @param {CSSProperties} [style] - Inline styles to apply.\n * @param {string} [id] - Unique identifier for the component.\n * @param {string} [data-testid] - A unique string that appears as data attribute `data-testid` in the rendered code.\n *\n * @component\n * @example\n * ```tsx\n * // Basic usage with negative sentiment\n * <SentimentSurface sentiment=\"negative\">\n * Your payment has failed\n * </SentimentSurface>\n * ```\n *\n * @see {@link SentimentSurface} for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/sentiment-surface--docs|Storybook Wise Design}\n */\n// @ts-expect-error - Generic forwardRef limitation. See: https://fettblog.eu/typescript-react-generic-forward-refs/\nconst SentimentSurface: SentimentSurfaceComponent = forwardRef(function SentimentSurface<\n T extends ElementType = 'div',\n>(\n {\n as,\n sentiment,\n emphasis = 'base',\n hasBaseStyles = true,\n style,\n className,\n children,\n id,\n 'data-testid': dataTestId,\n ...props\n }: SentimentSurfaceComponentProps<T>,\n ref: ForwardedRef<HTMLElement>,\n) {\n const Element = as ?? 'div';\n const BASE_CLASS = 'wds-sentiment-surface';\n const { className: closestBrandTheme, isScreenModeDark: isDark, theme } = useTheme();\n\n const getThemeBrightness = () => {\n const isForestGreen = theme.includes('forest-green');\n const isPlatform = theme.includes('platform');\n\n return isForestGreen || (isDark && !isPlatform) ? 'dark' : 'light';\n };\n\n const classNames = clsx(\n closestBrandTheme,\n BASE_CLASS,\n `wds-sentiment-${sentiment}-${getThemeBrightness()}-${emphasis}`,\n hasBaseStyles && `${BASE_CLASS}--hasBaseStyles`,\n className,\n );\n const sentimentProps = {\n ref,\n id,\n 'data-testid': dataTestId,\n className: classNames,\n style,\n ...props,\n };\n\n return (\n // @ts-expect-error - Generic forwardRef limitation. See: https://fettblog.eu/typescript-react-generic-forward-refs/\n <Element {...sentimentProps}>{children}</Element>\n );\n});\n\nSentimentSurface.displayName = 'SentimentSurface';\n\nexport default SentimentSurface;\n"],"names":["SentimentSurface","forwardRef","as","sentiment","emphasis","hasBaseStyles","style","className","children","id","dataTestId","props","ref","Element","BASE_CLASS","closestBrandTheme","isScreenModeDark","isDark","theme","useTheme","getThemeBrightness","isForestGreen","includes","isPlatform","classNames","clsx","sentimentProps","_jsx","displayName"],"mappings":";;;;;;;;;AAqCA,MAAMA,gBAAgB,gBAA8BC,gBAAU,CAAC,SAASD,gBAAgBA,CAGtF;EACEE,EAAE;EACFC,SAAS;AACTC,EAAAA,QAAQ,GAAG,MAAM;AACjBC,EAAAA,aAAa,GAAG,IAAI;EACpBC,KAAK;EACLC,SAAS;EACTC,QAAQ;EACRC,EAAE;AACF,EAAA,aAAa,EAAEC,UAAU;EACzB,GAAGC;AAAK,CAC0B,EACpCC,GAA8B,EAAA;AAE9B,EAAA,MAAMC,OAAO,GAAGX,EAAE,IAAI,KAAK;EAC3B,MAAMY,UAAU,GAAG,uBAAuB;EAC1C,MAAM;AAAEP,IAAAA,SAAS,EAAEQ,iBAAiB;AAAEC,IAAAA,gBAAgB,EAAEC,MAAM;AAAEC,IAAAA;GAAO,GAAGC,0BAAQ,EAAE;EAEpF,MAAMC,kBAAkB,GAAGA,MAAK;AAC9B,IAAA,MAAMC,aAAa,GAAGH,KAAK,CAACI,QAAQ,CAAC,cAAc,CAAC;AACpD,IAAA,MAAMC,UAAU,GAAGL,KAAK,CAACI,QAAQ,CAAC,UAAU,CAAC;IAE7C,OAAOD,aAAa,IAAKJ,MAAM,IAAI,CAACM,UAAW,GAAG,MAAM,GAAG,OAAO;EACpE,CAAC;EAED,MAAMC,UAAU,GAAGC,SAAI,CACrBV,iBAAiB,EACjBD,UAAU,EACV,CAAA,cAAA,EAAiBX,SAAS,CAAA,CAAA,EAAIiB,kBAAkB,EAAE,CAAA,CAAA,EAAIhB,QAAQ,CAAA,CAAE,EAChEC,aAAa,IAAI,CAAA,EAAGS,UAAU,CAAA,eAAA,CAAiB,EAC/CP,SAAS,CACV;AACD,EAAA,MAAMmB,cAAc,GAAG;IACrBd,GAAG;IACHH,EAAE;AACF,IAAA,aAAa,EAAEC,UAAU;AACzBH,IAAAA,SAAS,EAAEiB,UAAU;IACrBlB,KAAK;IACL,GAAGK;GACJ;AAED,EAAA;AAAA;AACE;AACAgB,IAAAA,cAAA,CAACd,OAAO,EAAA;AAAA,MAAA,GAAKa,cAAc;AAAAlB,MAAAA,QAAA,EAAGA;KAAkB;AAAC;AAErD,CAAC;AAEDR,gBAAgB,CAAC4B,WAAW,GAAG,kBAAkB;;;;"}
|
|
@@ -25,7 +25,7 @@ const SentimentSurface = /*#__PURE__*/forwardRef(function SentimentSurface({
|
|
|
25
25
|
const getThemeBrightness = () => {
|
|
26
26
|
const isForestGreen = theme.includes('forest-green');
|
|
27
27
|
const isPlatform = theme.includes('platform');
|
|
28
|
-
return
|
|
28
|
+
return isForestGreen || isDark && !isPlatform ? 'dark' : 'light';
|
|
29
29
|
};
|
|
30
30
|
const classNames = clsx(closestBrandTheme, BASE_CLASS, `wds-sentiment-${sentiment}-${getThemeBrightness()}-${emphasis}`, hasBaseStyles && `${BASE_CLASS}--hasBaseStyles`, className);
|
|
31
31
|
const sentimentProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SentimentSurface.mjs","sources":["../../src/sentimentSurface/SentimentSurface.tsx"],"sourcesContent":["import { forwardRef, ElementType, ForwardedRef } from 'react';\nimport { clsx } from 'clsx';\n\nimport {\n SentimentSurfaceComponentProps,\n SentimentSurfaceComponent,\n} from './SentimentSurface.types';\nimport { useTheme } from '@wise/components-theming';\n\n/**\n * SentimentSurface is a polymorphic container component that exposes and, optionally, applies\n * contextual colour tokens as CSS custom properties, based on sentiment types (`negative`,\n * `warning`, `neutral`, `success`, `proposition`).\n *\n * @param {ElementType} [as='div'] - Optional prop to override the HTML element rendered.\n * @param {Sentiment} sentiment - Required prop to set the sentiment type (negative, warning, neutral, success, proposition).\n * @param {Emphasis} [emphasis='base'] - Optional prop to specify the emphasis level (base or elevated).\n * @param {boolean} [hasBaseStyles=true] - If true, sets the `background-color` and `color` on the container. Otherwise, only exposes the tokens as CSS custom properties without rendering.\n * @param {ReactNode} [children] - Content to render inside the surface.\n * @param {string} [className] - Additional CSS classes to apply.\n * @param {CSSProperties} [style] - Inline styles to apply.\n * @param {string} [id] - Unique identifier for the component.\n * @param {string} [data-testid] - A unique string that appears as data attribute `data-testid` in the rendered code.\n *\n * @component\n * @example\n * ```tsx\n * // Basic usage with negative sentiment\n * <SentimentSurface sentiment=\"negative\">\n * Your payment has failed\n * </SentimentSurface>\n * ```\n *\n * @see {@link SentimentSurface} for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/sentiment-surface--docs|Storybook Wise Design}\n */\n// @ts-expect-error - Generic forwardRef limitation. See: https://fettblog.eu/typescript-react-generic-forward-refs/\nconst SentimentSurface: SentimentSurfaceComponent = forwardRef(function SentimentSurface<\n T extends ElementType = 'div',\n>(\n {\n as,\n sentiment,\n emphasis = 'base',\n hasBaseStyles = true,\n style,\n className,\n children,\n id,\n 'data-testid': dataTestId,\n ...props\n }: SentimentSurfaceComponentProps<T>,\n ref: ForwardedRef<HTMLElement>,\n) {\n const Element = as ?? 'div';\n const BASE_CLASS = 'wds-sentiment-surface';\n const { className: closestBrandTheme, isScreenModeDark: isDark, theme } = useTheme();\n\n const getThemeBrightness = () => {\n const isForestGreen = theme.includes('forest-green');\n const isPlatform = theme.includes('platform');\n\n return
|
|
1
|
+
{"version":3,"file":"SentimentSurface.mjs","sources":["../../src/sentimentSurface/SentimentSurface.tsx"],"sourcesContent":["import { forwardRef, ElementType, ForwardedRef } from 'react';\nimport { clsx } from 'clsx';\n\nimport {\n SentimentSurfaceComponentProps,\n SentimentSurfaceComponent,\n} from './SentimentSurface.types';\nimport { useTheme } from '@wise/components-theming';\n\n/**\n * SentimentSurface is a polymorphic container component that exposes and, optionally, applies\n * contextual colour tokens as CSS custom properties, based on sentiment types (`negative`,\n * `warning`, `neutral`, `success`, `proposition`).\n *\n * @param {ElementType} [as='div'] - Optional prop to override the HTML element rendered.\n * @param {Sentiment} sentiment - Required prop to set the sentiment type (negative, warning, neutral, success, proposition).\n * @param {Emphasis} [emphasis='base'] - Optional prop to specify the emphasis level (base or elevated).\n * @param {boolean} [hasBaseStyles=true] - If true, sets the `background-color` and `color` on the container. Otherwise, only exposes the tokens as CSS custom properties without rendering.\n * @param {ReactNode} [children] - Content to render inside the surface.\n * @param {string} [className] - Additional CSS classes to apply.\n * @param {CSSProperties} [style] - Inline styles to apply.\n * @param {string} [id] - Unique identifier for the component.\n * @param {string} [data-testid] - A unique string that appears as data attribute `data-testid` in the rendered code.\n *\n * @component\n * @example\n * ```tsx\n * // Basic usage with negative sentiment\n * <SentimentSurface sentiment=\"negative\">\n * Your payment has failed\n * </SentimentSurface>\n * ```\n *\n * @see {@link SentimentSurface} for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/sentiment-surface--docs|Storybook Wise Design}\n */\n// @ts-expect-error - Generic forwardRef limitation. See: https://fettblog.eu/typescript-react-generic-forward-refs/\nconst SentimentSurface: SentimentSurfaceComponent = forwardRef(function SentimentSurface<\n T extends ElementType = 'div',\n>(\n {\n as,\n sentiment,\n emphasis = 'base',\n hasBaseStyles = true,\n style,\n className,\n children,\n id,\n 'data-testid': dataTestId,\n ...props\n }: SentimentSurfaceComponentProps<T>,\n ref: ForwardedRef<HTMLElement>,\n) {\n const Element = as ?? 'div';\n const BASE_CLASS = 'wds-sentiment-surface';\n const { className: closestBrandTheme, isScreenModeDark: isDark, theme } = useTheme();\n\n const getThemeBrightness = () => {\n const isForestGreen = theme.includes('forest-green');\n const isPlatform = theme.includes('platform');\n\n return isForestGreen || (isDark && !isPlatform) ? 'dark' : 'light';\n };\n\n const classNames = clsx(\n closestBrandTheme,\n BASE_CLASS,\n `wds-sentiment-${sentiment}-${getThemeBrightness()}-${emphasis}`,\n hasBaseStyles && `${BASE_CLASS}--hasBaseStyles`,\n className,\n );\n const sentimentProps = {\n ref,\n id,\n 'data-testid': dataTestId,\n className: classNames,\n style,\n ...props,\n };\n\n return (\n // @ts-expect-error - Generic forwardRef limitation. See: https://fettblog.eu/typescript-react-generic-forward-refs/\n <Element {...sentimentProps}>{children}</Element>\n );\n});\n\nSentimentSurface.displayName = 'SentimentSurface';\n\nexport default SentimentSurface;\n"],"names":["SentimentSurface","forwardRef","as","sentiment","emphasis","hasBaseStyles","style","className","children","id","dataTestId","props","ref","Element","BASE_CLASS","closestBrandTheme","isScreenModeDark","isDark","theme","useTheme","getThemeBrightness","isForestGreen","includes","isPlatform","classNames","clsx","sentimentProps","_jsx","displayName"],"mappings":";;;;;AAqCA,MAAMA,gBAAgB,gBAA8BC,UAAU,CAAC,SAASD,gBAAgBA,CAGtF;EACEE,EAAE;EACFC,SAAS;AACTC,EAAAA,QAAQ,GAAG,MAAM;AACjBC,EAAAA,aAAa,GAAG,IAAI;EACpBC,KAAK;EACLC,SAAS;EACTC,QAAQ;EACRC,EAAE;AACF,EAAA,aAAa,EAAEC,UAAU;EACzB,GAAGC;AAAK,CAC0B,EACpCC,GAA8B,EAAA;AAE9B,EAAA,MAAMC,OAAO,GAAGX,EAAE,IAAI,KAAK;EAC3B,MAAMY,UAAU,GAAG,uBAAuB;EAC1C,MAAM;AAAEP,IAAAA,SAAS,EAAEQ,iBAAiB;AAAEC,IAAAA,gBAAgB,EAAEC,MAAM;AAAEC,IAAAA;GAAO,GAAGC,QAAQ,EAAE;EAEpF,MAAMC,kBAAkB,GAAGA,MAAK;AAC9B,IAAA,MAAMC,aAAa,GAAGH,KAAK,CAACI,QAAQ,CAAC,cAAc,CAAC;AACpD,IAAA,MAAMC,UAAU,GAAGL,KAAK,CAACI,QAAQ,CAAC,UAAU,CAAC;IAE7C,OAAOD,aAAa,IAAKJ,MAAM,IAAI,CAACM,UAAW,GAAG,MAAM,GAAG,OAAO;EACpE,CAAC;EAED,MAAMC,UAAU,GAAGC,IAAI,CACrBV,iBAAiB,EACjBD,UAAU,EACV,CAAA,cAAA,EAAiBX,SAAS,CAAA,CAAA,EAAIiB,kBAAkB,EAAE,CAAA,CAAA,EAAIhB,QAAQ,CAAA,CAAE,EAChEC,aAAa,IAAI,CAAA,EAAGS,UAAU,CAAA,eAAA,CAAiB,EAC/CP,SAAS,CACV;AACD,EAAA,MAAMmB,cAAc,GAAG;IACrBd,GAAG;IACHH,EAAE;AACF,IAAA,aAAa,EAAEC,UAAU;AACzBH,IAAAA,SAAS,EAAEiB,UAAU;IACrBlB,KAAK;IACL,GAAGK;GACJ;AAED,EAAA;AAAA;AACE;AACAgB,IAAAA,GAAA,CAACd,OAAO,EAAA;AAAA,MAAA,GAAKa,cAAc;AAAAlB,MAAAA,QAAA,EAAGA;KAAkB;AAAC;AAErD,CAAC;AAEDR,gBAAgB,CAAC4B,WAAW,GAAG,kBAAkB;;;;"}
|
package/package.json
CHANGED
|
@@ -183,6 +183,39 @@ describe('SentimentSurface', () => {
|
|
|
183
183
|
);
|
|
184
184
|
expect(screen.getByTestId('surface')).toHaveClass('wds-sentiment-neutral-light-base');
|
|
185
185
|
});
|
|
186
|
+
|
|
187
|
+
it('uses light mode class for np-theme-platform in light mode', () => {
|
|
188
|
+
render(
|
|
189
|
+
<ThemeProvider theme="platform" screenMode="light">
|
|
190
|
+
<SentimentSurface sentiment="neutral" data-testid="surface">
|
|
191
|
+
{testContent}
|
|
192
|
+
</SentimentSurface>
|
|
193
|
+
</ThemeProvider>,
|
|
194
|
+
);
|
|
195
|
+
expect(screen.getByTestId('surface')).toHaveClass('wds-sentiment-neutral-light-base');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('uses light mode class for np-theme-platform in dark mode', () => {
|
|
199
|
+
render(
|
|
200
|
+
<ThemeProvider theme="platform" screenMode="dark">
|
|
201
|
+
<SentimentSurface sentiment="neutral" data-testid="surface">
|
|
202
|
+
{testContent}
|
|
203
|
+
</SentimentSurface>
|
|
204
|
+
</ThemeProvider>,
|
|
205
|
+
);
|
|
206
|
+
expect(screen.getByTestId('surface')).toHaveClass('wds-sentiment-neutral-light-base');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('uses dark mode class for np-theme-platform--forest-green', () => {
|
|
210
|
+
render(
|
|
211
|
+
<ThemeProvider theme="platform--forest-green">
|
|
212
|
+
<SentimentSurface sentiment="negative" data-testid="surface">
|
|
213
|
+
{testContent}
|
|
214
|
+
</SentimentSurface>
|
|
215
|
+
</ThemeProvider>,
|
|
216
|
+
);
|
|
217
|
+
expect(screen.getByTestId('surface')).toHaveClass('wds-sentiment-negative-dark-base');
|
|
218
|
+
});
|
|
186
219
|
});
|
|
187
220
|
|
|
188
221
|
describe('HTML attributes', () => {
|
|
@@ -60,7 +60,7 @@ const SentimentSurface: SentimentSurfaceComponent = forwardRef(function Sentimen
|
|
|
60
60
|
const isForestGreen = theme.includes('forest-green');
|
|
61
61
|
const isPlatform = theme.includes('platform');
|
|
62
62
|
|
|
63
|
-
return
|
|
63
|
+
return isForestGreen || (isDark && !isPlatform) ? 'dark' : 'light';
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
const classNames = clsx(
|