@player-ui/reference-assets-plugin-react 0.8.0--canary.307.9621 → 0.8.0-next.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 (76) hide show
  1. package/dist/cjs/index.cjs +581 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.css +703 -0
  4. package/dist/index.legacy-esm.js +529 -0
  5. package/dist/index.mjs +529 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +34 -63
  8. package/src/__tests__/integration.test.tsx +158 -0
  9. package/src/assets/action/Action.tsx +10 -14
  10. package/src/assets/action/hooks.tsx +6 -6
  11. package/src/assets/action/index.ts +2 -2
  12. package/src/assets/choice/Choice.tsx +52 -0
  13. package/src/assets/choice/hooks.tsx +34 -0
  14. package/src/assets/choice/index.ts +2 -0
  15. package/src/assets/collection/Collection.tsx +6 -9
  16. package/src/assets/collection/index.tsx +1 -1
  17. package/src/assets/image/Image.tsx +4 -4
  18. package/src/assets/image/index.tsx +1 -1
  19. package/src/assets/index.tsx +7 -6
  20. package/src/assets/info/Info.tsx +26 -29
  21. package/src/assets/info/index.tsx +1 -1
  22. package/src/assets/input/Input.tsx +27 -19
  23. package/src/assets/input/hooks.tsx +35 -35
  24. package/src/assets/input/index.tsx +2 -2
  25. package/src/assets/input/types.ts +2 -2
  26. package/src/assets/text/Text.tsx +13 -7
  27. package/src/assets/text/hooks.tsx +6 -6
  28. package/src/assets/text/index.tsx +2 -2
  29. package/src/components/Button.tsx +56 -0
  30. package/src/components/ChoiceItem.tsx +31 -0
  31. package/src/components/Input.tsx +26 -0
  32. package/src/components/Label.tsx +26 -0
  33. package/src/components/Separator.tsx +30 -0
  34. package/src/global.css +83 -0
  35. package/src/index.tsx +4 -2
  36. package/src/intro.stories.mdx +9 -9
  37. package/src/plugin.tsx +22 -43
  38. package/src/utils.ts +6 -0
  39. package/types/assets/action/Action.d.ts +7 -0
  40. package/types/assets/action/hooks.d.ts +9 -0
  41. package/types/assets/action/index.d.ts +3 -0
  42. package/types/assets/choice/Choice.d.ts +6 -0
  43. package/types/assets/choice/hooks.d.ts +5 -0
  44. package/types/assets/choice/index.d.ts +3 -0
  45. package/types/assets/collection/Collection.d.ts +4 -0
  46. package/types/assets/collection/index.d.ts +2 -0
  47. package/types/assets/image/Image.d.ts +4 -0
  48. package/types/assets/image/index.d.ts +2 -0
  49. package/types/assets/index.d.ts +8 -0
  50. package/types/assets/info/Info.d.ts +5 -0
  51. package/types/assets/info/index.d.ts +2 -0
  52. package/types/assets/input/Input.d.ts +6 -0
  53. package/types/assets/input/hooks.d.ts +40 -0
  54. package/types/assets/input/index.d.ts +3 -0
  55. package/types/assets/input/types.d.ts +3 -0
  56. package/types/assets/text/Text.d.ts +7 -0
  57. package/types/assets/text/hooks.d.ts +9 -0
  58. package/types/assets/text/index.d.ts +3 -0
  59. package/types/components/Button.d.ts +12 -0
  60. package/types/components/ChoiceItem.d.ts +7 -0
  61. package/types/components/Input.d.ts +6 -0
  62. package/types/components/Label.d.ts +6 -0
  63. package/types/components/Separator.d.ts +5 -0
  64. package/types/index.d.ts +4 -0
  65. package/types/plugin.d.ts +19 -0
  66. package/types/utils.d.ts +3 -0
  67. package/dist/index.cjs.js +0 -501
  68. package/dist/index.d.ts +0 -94
  69. package/dist/index.esm.js +0 -479
  70. package/dist/xlr/ActionAsset.json +0 -126
  71. package/dist/xlr/CollectionAsset.json +0 -40
  72. package/dist/xlr/InfoAsset.json +0 -58
  73. package/dist/xlr/InputAsset.json +0 -109
  74. package/dist/xlr/TextAsset.json +0 -125
  75. package/dist/xlr/manifest.js +0 -16
  76. package/dist/xlr/manifest.json +0 -22
package/package.json CHANGED
@@ -1,73 +1,44 @@
1
1
  {
2
2
  "name": "@player-ui/reference-assets-plugin-react",
3
- "version": "0.8.0--canary.307.9621",
4
- "private": false,
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org"
7
- },
8
- "peerDependencies": {
9
- "@types/node": "^16.11.12",
10
- "@player-ui/react": "0.8.0--canary.307.9621"
11
- },
3
+ "version": "0.8.0-next.0",
4
+ "main": "dist/cjs/index.cjs",
12
5
  "dependencies": {
13
- "@player-ui/reference-assets-plugin": "0.8.0--canary.307.9621",
14
- "@player-ui/partial-match-registry": "0.8.0--canary.307.9621",
15
- "@player-ui/asset-provider-plugin-react": "0.8.0--canary.307.9621",
16
- "@player-ui/beacon-plugin-react": "0.8.0--canary.307.9621",
6
+ "@player-ui/asset-provider-plugin-react": "0.8.0-next.0",
7
+ "@player-ui/beacon-plugin-react": "0.8.0-next.0",
8
+ "@player-ui/partial-match-registry": "0.8.0-next.0",
9
+ "@player-ui/reference-assets-plugin": "0.8.0-next.0",
10
+ "@radix-ui/react-label": "^2.0.2",
11
+ "@radix-ui/react-separator": "^1.0.3",
12
+ "@radix-ui/react-slot": "^1.0.2",
13
+ "class-variance-authority": "^0.7.0",
17
14
  "clsx": "^1.1.1",
18
- "@chakra-ui/react": "^1.7.3",
19
- "@chakra-ui/icons": "^1.1.1",
20
- "@babel/runtime": "7.15.4"
15
+ "lucide-react": "^0.316.0",
16
+ "tailwind-merge": "^2.2.1",
17
+ "tslib": "^2.6.2"
21
18
  },
22
- "main": "dist/index.cjs.js",
23
- "module": "dist/index.esm.js",
24
- "typings": "dist/index.d.ts",
25
- "sideEffects": false,
26
- "license": "MIT",
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/player-ui/player-ui"
19
+ "devDependencies": {
20
+ "@player-ui/make-flow": "workspace:*"
30
21
  },
31
- "bugs": {
32
- "url": "https://github.com/player-ui/player-ui/issues"
22
+ "peerDependencies": {
23
+ "@player-ui/react": "0.8.0-next.0",
24
+ "react": "^18.2.0",
25
+ "@types/react": "^18.2.39"
33
26
  },
34
- "homepage": "https://player-ui.github.io",
35
- "contributors": [
36
- {
37
- "name": "Adam Dierkens",
38
- "url": "https://github.com/adierkens"
39
- },
40
- {
41
- "name": "Spencer Hamm",
42
- "url": "https://github.com/spentacular"
43
- },
44
- {
45
- "name": "Harris Borawski",
46
- "url": "https://github.com/hborawski"
47
- },
48
- {
49
- "name": "Jeremiah Zucker",
50
- "url": "https://github.com/sugarmanz"
51
- },
52
- {
53
- "name": "Ketan Reddy",
54
- "url": "https://github.com/KetanReddy"
55
- },
56
- {
57
- "name": "Brocollie08",
58
- "url": "https://github.com/brocollie08"
59
- },
60
- {
61
- "name": "Kelly Harrop",
62
- "url": "https://github.com/kharrop"
63
- },
64
- {
65
- "name": "Alejandro Fimbres",
66
- "url": "https://github.com/lexfm"
67
- },
68
- {
69
- "name": "Rafael Campos",
70
- "url": "https://github.com/rafbcampos"
27
+ "module": "dist/index.legacy-esm.js",
28
+ "types": "types/index.d.ts",
29
+ "sideEffects": false,
30
+ "exports": {
31
+ "./package.json": "./package.json",
32
+ "./dist/index.css": "./dist/index.css",
33
+ ".": {
34
+ "types": "./types/index.d.ts",
35
+ "import": "./dist/index.mjs",
36
+ "default": "./dist/cjs/index.cjs"
71
37
  }
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "src",
42
+ "types"
72
43
  ]
73
44
  }
@@ -0,0 +1,158 @@
1
+ import { describe, test, vitest, expect, beforeEach } from "vitest";
2
+ import React from "react";
3
+ import {
4
+ screen,
5
+ render,
6
+ act,
7
+ fireEvent,
8
+ waitFor,
9
+ configure,
10
+ } from "@testing-library/react";
11
+ import { BeaconPlugin } from "@player-ui/beacon-plugin-react";
12
+ import { ReactPlayer } from "@player-ui/react";
13
+ import { makeFlow } from "@player-ui/make-flow";
14
+ import { ReferenceAssetsPlugin } from "../plugin";
15
+
16
+ configure({
17
+ testIdAttribute: "id",
18
+ });
19
+
20
+ describe("Integration tests", () => {
21
+ describe("Input", () => {
22
+ test("beacons the correct custom data value", async () => {
23
+ const handler = vitest.fn();
24
+ const beaconPlugin = new BeaconPlugin({ callback: handler });
25
+
26
+ const rp = new ReactPlayer({
27
+ plugins: [beaconPlugin, new ReferenceAssetsPlugin()],
28
+ });
29
+
30
+ const flow = makeFlow({
31
+ id: "first_view",
32
+ type: "input",
33
+ binding: "foo.bar",
34
+ metaData: { beacon: { custom_data: "{{foo.bar}}" } },
35
+ });
36
+
37
+ render(
38
+ <React.Suspense fallback="fallback">
39
+ <rp.Component />
40
+ </React.Suspense>,
41
+ );
42
+
43
+ await act(async () => {
44
+ rp.start(flow);
45
+ });
46
+
47
+ const viewNode = await screen.findByTestId("first_view");
48
+
49
+ act(() => {
50
+ fireEvent.change(viewNode, { target: { value: "new value" } });
51
+ });
52
+
53
+ act(() => {
54
+ fireEvent.blur(viewNode, { target: { value: "new value" } });
55
+ });
56
+
57
+ await waitFor(() => {
58
+ expect(handler.mock.calls).toHaveLength(2);
59
+ });
60
+
61
+ expect(handler.mock.calls[1][0]).toMatchObject({
62
+ assetId: "first_view",
63
+ data: { custom_data: "new value" },
64
+ });
65
+ });
66
+ });
67
+
68
+ describe("Choice", () => {
69
+ let handler, beaconPlugin, rp, items, flow;
70
+
71
+ beforeEach(async () => {
72
+ handler = vitest.fn();
73
+ beaconPlugin = new BeaconPlugin({ callback: handler });
74
+
75
+ rp = new ReactPlayer({
76
+ plugins: [beaconPlugin, new ReferenceAssetsPlugin()],
77
+ });
78
+
79
+ items = [
80
+ {
81
+ id: "item-1",
82
+ value: "Item 1",
83
+ label: {
84
+ asset: {
85
+ id: "choice-without-note-items-0-label",
86
+ type: "text",
87
+ value: "Item 1",
88
+ },
89
+ },
90
+ },
91
+ {
92
+ id: "item-2",
93
+ value: "Item 2",
94
+ label: {
95
+ asset: {
96
+ id: "choice-without-note-items-1-label",
97
+ type: "text",
98
+ value: "Item 2",
99
+ },
100
+ },
101
+ },
102
+ ];
103
+
104
+ flow = makeFlow({
105
+ id: "choice",
106
+ type: "choice",
107
+ binding: "foo.bar",
108
+ metaData: { beacon: { custom_data: "{{foo.bar}}" } },
109
+ items,
110
+ });
111
+
112
+ render(
113
+ <React.Suspense fallback="fallback">
114
+ <rp.Component />
115
+ </React.Suspense>,
116
+ );
117
+
118
+ await act(async () => {
119
+ rp.start(flow);
120
+ });
121
+ });
122
+
123
+ test("beacon handler is called on each item click", async () => {
124
+ for (const item of items) {
125
+ const itemNode = await screen.findByTestId(item.id);
126
+
127
+ act(() => {
128
+ fireEvent.click(itemNode);
129
+ });
130
+
131
+ await waitFor(() => {
132
+ expect(handler.mock.calls).toHaveLength(2);
133
+ });
134
+
135
+ expect(handler.mock.calls[1][0]).toMatchObject({
136
+ assetId: "choice",
137
+ action: "clicked",
138
+ });
139
+ }
140
+ });
141
+
142
+ test("each item is set to checked on click", async () => {
143
+ for (const item of items) {
144
+ let itemNode;
145
+
146
+ itemNode = await screen.findByTestId(item.id);
147
+ expect(itemNode.checked).toEqual(false);
148
+
149
+ act(() => {
150
+ fireEvent.click(itemNode);
151
+ });
152
+
153
+ itemNode = await screen.findByTestId(item.id);
154
+ expect(itemNode.checked).toEqual(true);
155
+ }
156
+ });
157
+ });
158
+ });
@@ -1,10 +1,10 @@
1
- import React from 'react';
2
- import { ReactAsset } from '@player-ui/react';
3
- import { Button, Text } from '@chakra-ui/react';
4
- import { ChevronLeftIcon } from '@chakra-ui/icons';
5
- import type { TransformedAction } from '@player-ui/reference-assets-plugin';
6
- import { isBackAction } from '@player-ui/reference-assets-plugin';
7
- import { useAction } from './hooks';
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import { ChevronLeftIcon } from "lucide-react";
4
+ import type { TransformedAction } from "@player-ui/reference-assets-plugin";
5
+ import { isBackAction } from "@player-ui/reference-assets-plugin";
6
+ import { useAction } from "./hooks";
7
+ import { Button } from "../../components/Button";
8
8
 
9
9
  /**
10
10
  * An action that a user can take
@@ -16,15 +16,11 @@ export const Action = (props: TransformedAction) => {
16
16
  return (
17
17
  <div>
18
18
  <Button
19
- variant={isBackAction(props) ? 'ghost' : 'solid'}
19
+ variant={isBackAction(props) ? "outline" : undefined}
20
20
  {...buttonProps}
21
21
  >
22
- {props?.metaData?.role === 'back' && <ChevronLeftIcon />}
23
- {label && (
24
- <Text>
25
- <ReactAsset {...label} />
26
- </Text>
27
- )}
22
+ {props?.metaData?.role === "back" && <ChevronLeftIcon />}
23
+ {label && <ReactAsset {...label} />}
28
24
  </Button>
29
25
  </div>
30
26
  );
@@ -1,15 +1,15 @@
1
- import React from 'react';
2
- import { ReactAsset } from '@player-ui/react';
3
- import { useBeacon } from '@player-ui/beacon-plugin-react';
4
- import type { TransformedAction } from '@player-ui/reference-assets-plugin';
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import { useBeacon } from "@player-ui/beacon-plugin-react";
4
+ import type { TransformedAction } from "@player-ui/reference-assets-plugin";
5
5
 
6
6
  /** Hook to get all the props for a button */
7
7
  export const useAction = (props: TransformedAction) => {
8
8
  const { label } = props;
9
9
  const beacon = useBeacon({
10
10
  asset: props,
11
- action: 'clicked',
12
- element: 'button',
11
+ action: "clicked",
12
+ element: "button",
13
13
  });
14
14
 
15
15
  return {
@@ -1,2 +1,2 @@
1
- export * from './Action';
2
- export * from './hooks';
1
+ export * from "./Action";
2
+ export * from "./hooks";
@@ -0,0 +1,52 @@
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import type { TransformedChoice } from "@player-ui/reference-assets-plugin";
4
+ import { ChoiceItem } from "../../components/ChoiceItem";
5
+ import { Label } from "../../components/Label";
6
+ import type { ChoiceItemProps } from "../../components/ChoiceItem";
7
+
8
+ import { useChoiceItems } from "./hooks";
9
+
10
+ /** A Choice */
11
+ export const Choice = (props: TransformedChoice) => {
12
+ const { validation, title, id, note } = props;
13
+ const choiceItemProps: Array<ChoiceItemProps> = useChoiceItems(props);
14
+
15
+ const renderChoices = () =>
16
+ choiceItemProps.map((choiceItemProp) => (
17
+ <ChoiceItem key={choiceItemProp.id} {...choiceItemProp} />
18
+ ));
19
+
20
+ return (
21
+ <div className="grid w-full max-w-sm items-center gap-3">
22
+ {title && (
23
+ <Label htmlFor={id}>
24
+ <ReactAsset {...title} />
25
+ </Label>
26
+ )}
27
+ <div
28
+ id={props.id}
29
+ className="grid gap-2"
30
+ aria-invalid={Boolean(validation)}
31
+ aria-describedby={validation ? `${id}-validation` : undefined}
32
+ >
33
+ {renderChoices()}
34
+ </div>
35
+ {validation && (
36
+ <Label
37
+ id={`${id}-validation`}
38
+ className="text-[0.8rem] font-medium text-destructive"
39
+ >
40
+ {validation.message}
41
+ </Label>
42
+ )}
43
+ {note && (
44
+ <Label className="text-[0.8rem] text-muted-foreground">
45
+ <ReactAsset {...note} />
46
+ </Label>
47
+ )}
48
+ </div>
49
+ );
50
+ };
51
+
52
+ export default Choice;
@@ -0,0 +1,34 @@
1
+ import { useBeacon } from "@player-ui/beacon-plugin-react";
2
+ import type {
3
+ TransformedChoice,
4
+ TransformedChoiceItem,
5
+ } from "@player-ui/reference-assets-plugin";
6
+ import type { ChoiceItemProps } from "../../components/ChoiceItem";
7
+
8
+ /** Hook to get the props for all choice asset items */
9
+ export const useChoiceItems = (
10
+ props: TransformedChoice,
11
+ ): Array<ChoiceItemProps> => {
12
+ const beacon = useBeacon({
13
+ asset: props,
14
+ action: "clicked",
15
+ element: "choice",
16
+ });
17
+
18
+ return (
19
+ props.items?.map((item: TransformedChoiceItem) => {
20
+ const { id, value, label } = item;
21
+ return {
22
+ id,
23
+ label,
24
+ name: props.id,
25
+ value: (value ?? "").toString(),
26
+ checked: value === props.value,
27
+ onChange: () => {
28
+ beacon();
29
+ item.select();
30
+ },
31
+ };
32
+ }) ?? []
33
+ );
34
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./Choice";
2
+ export * from "./hooks";
@@ -1,19 +1,16 @@
1
- import React from 'react';
2
- import { Flex } from '@chakra-ui/react';
3
- import { ReactAsset } from '@player-ui/react';
4
- import type { CollectionAsset } from '@player-ui/reference-assets-plugin';
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import type { CollectionAsset } from "@player-ui/reference-assets-plugin";
5
4
 
6
5
  export const Collection = (props: CollectionAsset) => {
7
6
  return (
8
- <Flex direction="column" gap="5">
7
+ <div className="flex flex-col gap-4">
9
8
  {props.label && (
10
9
  <h3>
11
10
  <ReactAsset {...props.label} />
12
11
  </h3>
13
12
  )}
14
- {props.values?.map((a) => (
15
- <ReactAsset key={a.asset.id} {...a} />
16
- ))}
17
- </Flex>
13
+ {props.values?.map((a) => <ReactAsset key={a.asset.id} {...a} />)}
14
+ </div>
18
15
  );
19
16
  };
@@ -1 +1 @@
1
- export * from './Collection';
1
+ export * from "./Collection";
@@ -1,10 +1,10 @@
1
- import React from 'react';
2
- import { ReactAsset } from '@player-ui/react';
3
- import type { TransformedImage } from '@player-ui/reference-assets-plugin';
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import type { TransformedImage } from "@player-ui/reference-assets-plugin";
4
4
 
5
5
  export const Image = (props: TransformedImage) => {
6
6
  const { metaData, caption, altText } = props;
7
- console.log(props);
7
+
8
8
  return (
9
9
  <figure className="figure">
10
10
  <img className="figure-img img-fluid" src={metaData.ref} alt={altText} />
@@ -1 +1 @@
1
- export * from './Image';
1
+ export * from "./Image";
@@ -1,6 +1,7 @@
1
- export * from './input';
2
- export * from './text';
3
- export * from './collection';
4
- export * from './action';
5
- export * from './info';
6
- export * from './image';
1
+ export * from "./input";
2
+ export * from "./text";
3
+ export * from "./collection";
4
+ export * from "./action";
5
+ export * from "./info";
6
+ export * from "./image";
7
+ export * from "./choice";
@@ -1,47 +1,44 @@
1
- import React from 'react';
2
- import type { InfoAssetTransform } from '@player-ui/reference-assets-plugin';
3
- import { ReactAsset } from '@player-ui/react';
4
- import {
5
- ButtonGroup,
6
- Box,
7
- Heading,
8
- Divider,
9
- Stack,
10
- HStack,
11
- } from '@chakra-ui/react';
1
+ import React from "react";
2
+ import type { InfoAssetTransform } from "@player-ui/reference-assets-plugin";
3
+ import { ReactAsset } from "@player-ui/react";
4
+ import { Separator } from "../../components/Separator";
12
5
 
13
6
  /** The info view type is used to show information to the user */
14
7
  export const Info = (props: InfoAssetTransform) => {
15
8
  return (
16
- <Box minW={{ base: undefined, md: 'md' }}>
17
- <Stack gap="10">
9
+ <div className="max-w-full">
10
+ <div className="flex flex-col gap-4">
18
11
  {props.title && (
19
- <Heading size="lg" as="h1">
12
+ <h1 className="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
20
13
  <ReactAsset {...props.title} />
21
- </Heading>
14
+ </h1>
22
15
  )}
23
16
  {props.subTitle && (
24
- <Heading size="md" as="h3">
17
+ <h3 className="scroll-m-20 text-2xl font-semibold tracking-tight">
25
18
  <ReactAsset {...props.subTitle} />
26
- </Heading>
19
+ </h3>
27
20
  )}
28
- <Box>{props.primaryInfo && <ReactAsset {...props.primaryInfo} />}</Box>
29
- <Stack gap="4">
30
- {props?.segmentedActions && <Divider />}
31
- <HStack justifyContent="space-between">
32
- <ButtonGroup spacing="6">
21
+ {props.primaryInfo && (
22
+ <div>
23
+ <ReactAsset {...props.primaryInfo} />
24
+ </div>
25
+ )}
26
+ <div className="flex flex-col gap-4">
27
+ {props?.segmentedActions && <Separator />}
28
+ <div className="flex justify-between sm:flex-row flex-col-reverse gap-4">
29
+ <div className="flex gap-4">
33
30
  {props?.segmentedActions?.prev?.map((a) => (
34
31
  <ReactAsset key={a.asset.id} {...a} />
35
32
  ))}
36
- </ButtonGroup>
37
- <ButtonGroup spacing="6">
33
+ </div>
34
+ <div className="flex gap-4">
38
35
  {props?.segmentedActions?.next?.map((a) => (
39
36
  <ReactAsset key={a.asset.id} {...a} />
40
37
  ))}
41
- </ButtonGroup>
42
- </HStack>
43
- </Stack>
44
- </Stack>
45
- </Box>
38
+ </div>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ </div>
46
43
  );
47
44
  };
@@ -1 +1 @@
1
- export * from './Info';
1
+ export * from "./Info";
@@ -1,14 +1,10 @@
1
- import React from 'react';
2
- import { ReactAsset } from '@player-ui/react';
3
- import type { TransformedInput } from '@player-ui/reference-assets-plugin';
4
- import {
5
- Input as ChakraInput,
6
- FormControl,
7
- FormLabel,
8
- FormErrorMessage,
9
- FormHelperText,
10
- } from '@chakra-ui/react';
11
- import { useInputAsset } from './hooks';
1
+ import React from "react";
2
+ import { ReactAsset } from "@player-ui/react";
3
+ import type { TransformedInput } from "@player-ui/reference-assets-plugin";
4
+ import { Input as InputComp } from "../../components/Input";
5
+ import { Label } from "../../components/Label";
6
+
7
+ import { useInputAsset } from "./hooks";
12
8
 
13
9
  /** An Input */
14
10
  export const Input = (props: TransformedInput) => {
@@ -16,20 +12,32 @@ export const Input = (props: TransformedInput) => {
16
12
  const inputProps = useInputAsset(props);
17
13
 
18
14
  return (
19
- <FormControl isInvalid={Boolean(validation)}>
15
+ <div className="grid w-full max-w-sm items-center gap-1.5">
20
16
  {label && (
21
- <FormLabel htmlFor={id}>
17
+ <Label htmlFor={id}>
22
18
  <ReactAsset {...label} />
23
- </FormLabel>
19
+ </Label>
20
+ )}
21
+ <InputComp
22
+ id={id}
23
+ aria-invalid={Boolean(validation)}
24
+ aria-describedby={validation ? `${id}-validation` : undefined}
25
+ {...inputProps}
26
+ />
27
+ {validation && (
28
+ <Label
29
+ id={`${id}-validation`}
30
+ className="text-[0.8rem] font-medium text-destructive"
31
+ >
32
+ {validation.message}
33
+ </Label>
24
34
  )}
25
- <ChakraInput id={id} size="md" {...inputProps} />
26
- {validation && <FormErrorMessage>{validation.message}</FormErrorMessage>}
27
35
  {note && (
28
- <FormHelperText>
36
+ <Label className="text-[0.8rem] text-muted-foreground">
29
37
  <ReactAsset {...note} />
30
- </FormHelperText>
38
+ </Label>
31
39
  )}
32
- </FormControl>
40
+ </div>
33
41
  );
34
42
  };
35
43