Skip to content

Commit 8516acf

Browse files
committedMay 1, 2024·
Plup script improvement/ Radiogroup DSL test pass
1 parent 99100fa commit 8516acf

File tree

13 files changed

+67
-80
lines changed

13 files changed

+67
-80
lines changed
 

‎docs/site/config/navigation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ const navigation: Navigation = {
8282
path: '/assets/toggle',
8383
},
8484
{
85-
title: 'RadioGroup',
86-
path: '/assets/radioGroup',
85+
title: 'Radio Group',
86+
path: '/assets/radio-group',
8787
},
8888
]
8989
},

‎docs/site/pages/assets/radioGroup.mdx renamed to ‎docs/site/pages/assets/radio-group.mdx

-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,3 @@ export class AssetsRegistryPlugin implements ReactPlayerPlugin, ExtendedPlayerPl
9292
}
9393
}
9494
```
95-
96-
## Contributing
97-
98-
We welcome contributions to `@devtools-ui/radio-group`! Please see the [CONTRIBUTING.md](TODO: link to the file) file for more information on how to contribute.

‎docs/storybook/src/assets/RadioGroup.stories.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ const meta: Meta<typeof RadioGroup> = {
99

1010
export default meta;
1111

12-
export const Basic = createDSLStory(() => import("../flows/radio-group/basic?raw"));
13-
14-
12+
export const Basic = createDSLStory(
13+
() => import("../flows/radio-group/basic?raw")
14+
);

‎plopfile.mjs

+10-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default function (plop) {
3939

4040
plop.setHelper("kebabCase", toKebabCase);
4141

42+
plop.setHelper("spacedPascal", toSpacedPascal)
43+
4244
plop.setGenerator("asset", {
4345
description: "Create a new asset",
4446
prompts: [
@@ -71,6 +73,11 @@ export default function (plop) {
7173
.replace(/^-/, "") // remove leading - if any
7274
.toLowerCase(); // Converting all to lowercase
7375
}
76+
77+
function toSpacedPascal(text) {
78+
return text
79+
.replace(/(?<=[a-z])([A-Z])/g, " $1") // adds space before inner capitalized lettes in pascal-cased words
80+
}
7481
}
7582

7683
const extendedActions = {
@@ -91,16 +98,16 @@ const extendedActions = {
9198
},
9299
mdxDocsiteDoc: {
93100
type: "add",
94-
path: "./docs/site/pages/assets/{{camelCase assetName}}.mdx",
101+
path: "./docs/site/pages/assets/{{kebabCase assetName}}.mdx",
95102
templateFile: "./asset-template/README.md.hbs",
96103
},
97104
mdxDocsiteNavigation: {
98105
type: "append",
99106
path: "./docs/site/config/navigation.ts",
100107
pattern: /(?=\s+])/,
101108
template: ` {
102-
title: '{{pascalCase assetName}}',
103-
path: '/assets/{{camelCase assetName}}',
109+
title: '{{spacedPascal (pascalCase assetName)}}',
110+
path: '/assets/{{kebabCase assetName}}',
104111
},`,
105112
},
106113
linkingAssetToSBPreviewImport: {

‎plugin/src/plugins/AssetsRegistryPlugin.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class AssetsRegistryPlugin
6262
CopyToClipboardAsset,
6363
CodeEditorAsset,
6464
ToggleAsset,
65-
RadioGroupAsset,
65+
RadioGroupAsset
6666
]
6767
>
6868
{

‎pnpm-lock.yaml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎radio-group/BUILD

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ js_pipeline(
2727
"//:node_modules/@player-ui/types",
2828
"//:node_modules/@types/react",
2929
"//:node_modules/dlv",
30-
"//:node_modules/eslint-plugin-storybook",
3130
"//:node_modules/framer-motion",
3231
"//:node_modules/react",
3332
],

‎radio-group/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,3 @@ export class AssetsRegistryPlugin implements ReactPlayerPlugin, ExtendedPlayerPl
9393
}
9494
```
9595

96-
## Contributing
97-
98-
We welcome contributions to `@devtools-ui/radio-group`! Please see the [CONTRIBUTING.md](TODO: link to the file) file for more information on how to contribute.

‎radio-group/src/component/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export const RadioGroupComponent = (props: TransformedRadioGroup) => {
1717
const { children, ...rest } = useRadioGroupProps(props);
1818

1919
// Replace with the Elements that render your component:
20-
return <div {...rest}>{children}</div>;
20+
return <div {...rest}>Something</div>;
2121
};

‎radio-group/src/dsl/__tests__/index.test.tsx

+13-24
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,18 @@ import {
99
import { RadioGroup } from "../";
1010

1111
describe("DSL: RadioGroup", () => {
12-
test("Renders radioGroup", async () => {
12+
test("Renders radioGroup with a couple options", async () => {
1313
const rendered = await render(
14-
<RadioGroup exp={e`my_expression`} binding={b`my_binding`}>
15-
<RadioGroup.Label>
16-
<Asset type="text">
17-
<property name="value">Label</property>
18-
</Asset>
19-
</RadioGroup.Label>
20-
<RadioGroup.Value>
21-
<Asset type="text">
22-
<property name="value">Value</property>
23-
</Asset>
24-
</RadioGroup.Value>
14+
<RadioGroup binding={b`my_binding`}>
15+
<RadioGroup.Label>RadioGroup Label</RadioGroup.Label>
2516
<RadioGroup.Values>
2617
<Asset type="text">
27-
<property name="value">Test 1</property>
18+
<property name="value">Option 1</property>
19+
<property name="radio">opt1</property>
2820
</Asset>
2921
<Asset type="text">
30-
<property name="value">Test 2</property>
22+
<property name="value">Option 2</property>
23+
<property name="radio">opt2</property>
3124
</Asset>
3225
</RadioGroup.Values>
3326
</RadioGroup>
@@ -36,33 +29,29 @@ describe("DSL: RadioGroup", () => {
3629
expect(rendered.jsonValue).toStrictEqual({
3730
id: "root",
3831
type: "radio-group",
32+
binding: "my_binding",
3933
label: {
4034
asset: {
4135
id: "label",
4236
type: "text",
43-
value: "Label",
44-
},
45-
},
46-
value: {
47-
asset: {
48-
id: "value",
49-
type: "text",
50-
value: "Value",
37+
value: "RadioGroup Label",
5138
},
5239
},
5340
values: [
5441
{
5542
asset: {
5643
id: "values-0",
5744
type: "text",
58-
value: "Test 1",
45+
value: "Option 1",
46+
radio: "opt1",
5947
},
6048
},
6149
{
6250
asset: {
6351
id: "values-1",
6452
type: "text",
65-
value: "Test 2",
53+
value: "Option 2",
54+
radio: "opt2",
6655
},
6756
},
6857
],

‎radio-group/src/dsl/index.tsx

-13
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import { Collection } from "@devtools-ui/collection";
1010
import { Text } from "@devtools-ui/text";
1111
import type { RadioGroupAsset } from "../types";
1212

13-
/**
14-
* Defines the component DSL representation, so users of this plugin can author Player-UI
15-
* content leveraging .jsx/.tsx syntax.
16-
*/
1713
export const RadioGroup = (
1814
props: Omit<AssetPropsWithChildren<RadioGroupAsset>, "binding"> & {
1915
/** The binding as a tagged template instance */
@@ -46,19 +42,10 @@ RadioGroup.Label = createSlot({
4642
wrapInAsset: true,
4743
});
4844

49-
RadioGroup.Value = createSlot({
50-
name: "value",
51-
TextComp: Text,
52-
CollectionComp,
53-
isArray: false,
54-
wrapInAsset: true,
55-
});
56-
5745
RadioGroup.Values = createSlot({
5846
name: "values",
5947
TextComp: Text,
6048
CollectionComp,
6149
isArray: true,
6250
wrapInAsset: true,
6351
});
64-

‎radio-group/src/transform/index.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import type { TransformFunction } from "@player-ui/player";
22
import { RadioGroupAsset, TransformedRadioGroup } from "../types";
33

4-
/**
5-
* Platform-agnostic transform function that takes the properties we get from the Player Content (DSL > JSON)
6-
* and embeds Player state and methods:
7-
*/
8-
export const radioGroupTransform: TransformFunction<RadioGroupAsset, TransformedRadioGroup> = (
9-
asset,
10-
options
11-
) => {
12-
// GET/SET properties from the data model and/or embed Player methods
13-
// e.g.: options.data.model.get(asset.binding, { includeInvalid: true, formatted: false });
14-
// e.g.: options.evaluate(asset.exp);
15-
// e.g.: options.transition?.(asset.value, { force: skipValidation });
4+
export const radioGroupTransform: TransformFunction<
5+
RadioGroupAsset,
6+
TransformedRadioGroup
7+
> = (asset, options) => {
168
return {
179
...asset,
10+
setRadio(val) {
11+
if (asset.binding === undefined) {
12+
return;
13+
}
14+
15+
return options.data.model.set([[asset.binding, val]]);
16+
},
17+
value:
18+
asset.binding === undefined ? "" : options.data.model.get(asset.binding),
1819
};
1920
};

‎radio-group/src/types/index.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import type { Asset } from "@player-ui/types";
1+
import type { Asset, AssetWrapper } from "@player-ui/types";
2+
import type { TextAsset } from "@devtools-ui/text";
23

34
export interface RadioGroupAsset extends Asset<"radio-group"> {
4-
// DSL properties
5-
// /** Value */
6-
// value?: AssetWrapper;
7-
// /** list of assets in the collection */
8-
// values?: Array<AssetWrapper>;
9-
// /** Label */
10-
// label?: AssetWrapper<TextAsset>;
11-
// /** Callable function that allow dynamic behavior for the view */
12-
// exp?: Expression;
13-
// /** Dot sepparated string Representation of a path within the data-model */
14-
// binding?: string;
5+
/** list of assets in the collection */
6+
values?: Array<AssetWrapper>;
7+
/** Label */
8+
label?: AssetWrapper<TextAsset>;
9+
/** Dot sepparated string Representation of a path within the data-model */
10+
binding?: string;
1511
}
1612

1713
/** A stateful instance of the asset */
1814
export interface TransformedRadioGroup extends RadioGroupAsset {
19-
// The result of the transformation (transform/index.ts)
15+
/** A function to commit the new value to the data-model */
16+
setRadio: (newValue: boolean) => void;
17+
/** The current value of the radio group from the data-model */
18+
value: string;
2019
}

0 commit comments

Comments
 (0)
Please sign in to comment.