@transferwise/components 46.57.0 → 46.58.0

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.
Files changed (41) hide show
  1. package/build/field/Field.js +1 -1
  2. package/build/field/Field.js.map +1 -1
  3. package/build/field/Field.mjs +1 -1
  4. package/build/field/Field.mjs.map +1 -1
  5. package/build/index.js +2 -0
  6. package/build/index.js.map +1 -1
  7. package/build/index.mjs +1 -0
  8. package/build/index.mjs.map +1 -1
  9. package/build/moneyInput/MoneyInput.js +8 -3
  10. package/build/moneyInput/MoneyInput.js.map +1 -1
  11. package/build/moneyInput/MoneyInput.mjs +8 -3
  12. package/build/moneyInput/MoneyInput.mjs.map +1 -1
  13. package/build/types/index.d.ts +5 -0
  14. package/build/types/index.d.ts.map +1 -1
  15. package/build/types/moneyInput/MoneyInput.d.ts +7 -3
  16. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  17. package/build/types/withId/index.d.ts +3 -0
  18. package/build/types/withId/index.d.ts.map +1 -0
  19. package/build/types/withId/story/source.d.ts +2 -0
  20. package/build/types/withId/story/source.d.ts.map +1 -0
  21. package/build/types/withId/withId.d.ts +17 -0
  22. package/build/types/withId/withId.d.ts.map +1 -0
  23. package/build/withId/withId.js +19 -0
  24. package/build/withId/withId.js.map +1 -0
  25. package/build/withId/withId.mjs +17 -0
  26. package/build/withId/withId.mjs.map +1 -0
  27. package/package.json +3 -3
  28. package/src/field/Field.spec.tsx +1 -1
  29. package/src/field/Field.story.tsx +19 -8
  30. package/src/field/Field.tsx +1 -1
  31. package/src/index.ts +6 -0
  32. package/src/inlineAlert/InlineAlert.story.tsx +10 -23
  33. package/src/moneyInput/MoneyInput.spec.js +19 -6
  34. package/src/moneyInput/MoneyInput.story.tsx +8 -9
  35. package/src/moneyInput/MoneyInput.tsx +8 -5
  36. package/src/withId/index.ts +2 -0
  37. package/src/withId/story/source.tsx +22 -0
  38. package/src/withId/withId.docs.mdx +33 -0
  39. package/src/withId/withId.spec.tsx +28 -0
  40. package/src/withId/withId.story.tsx +41 -0
  41. package/src/withId/withId.tsx +27 -0
@@ -0,0 +1,41 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { Button, withId, type WithIdProps } from '..';
3
+
4
+ type Story = StoryObj<typeof withId>;
5
+
6
+ type DescribedButtonProps = { id?: string };
7
+ type DescribedButtonWithIdProps = WithIdProps<DescribedButtonProps>;
8
+
9
+ function CustomButton({ id }: DescribedButtonWithIdProps) {
10
+ return (
11
+ <>
12
+ <Button aria-describedby={id}>Continue</Button>
13
+
14
+ <p id={id} className="text-xs-center m-t-2">
15
+ Enter an amount in either GBP or PLN
16
+ <br />
17
+ This paragraph has id of <code>{id}</code>
18
+ </p>
19
+ </>
20
+ );
21
+ }
22
+ const DescribedButton = withId<DescribedButtonProps>(CustomButton);
23
+ DescribedButton.displayName = 'DescribedButton';
24
+
25
+ export default {
26
+ component: DescribedButton,
27
+ } satisfies Meta<typeof withId>;
28
+
29
+ export const WithoutId: Story = {};
30
+
31
+ export const WithCustomId: Story = {
32
+ args: {
33
+ id: 'myId',
34
+ },
35
+ };
36
+
37
+ export const WithEmptyId: Story = {
38
+ args: {
39
+ id: '',
40
+ },
41
+ };
@@ -0,0 +1,27 @@
1
+ import { useId, ComponentType } from 'react';
2
+
3
+ type ChildProps<Props> = Props & {
4
+ id?: string;
5
+ };
6
+
7
+ export type WithIdProps<Props> = Props & {
8
+ id: string;
9
+ };
10
+
11
+ /**
12
+ * @internal
13
+ * @param {ReactNode} WrappedComponent
14
+ */
15
+ export default function withId<Props extends object>(
16
+ WrappedComponent: ComponentType<WithIdProps<Props>>,
17
+ ) {
18
+ function WithIdComponent(props: ChildProps<Props>) {
19
+ const id = useId();
20
+
21
+ return <WrappedComponent {...props} id={props.id || id} />;
22
+ }
23
+
24
+ WithIdComponent.displayName = `withId(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
25
+
26
+ return WithIdComponent;
27
+ }