@plasmicpkgs/react-aria 0.0.64 → 0.0.65
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/dist/.tsbuildinfo +1 -1
- package/dist/react-aria.esm.js +4 -2
- package/dist/react-aria.esm.js.map +1 -1
- package/dist/react-aria.js +4 -2
- package/dist/react-aria.js.map +1 -1
- package/package.json +2 -2
- package/skinny/registerListBoxItem.cjs.js +4 -2
- package/skinny/registerListBoxItem.cjs.js.map +1 -1
- package/skinny/registerListBoxItem.esm.js +4 -2
- package/skinny/registerListBoxItem.esm.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/react-aria",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"description": "Plasmic registration calls for react-aria based components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "0203141dd0a61cf9d6a5d3c8e0cef9d93d4e8292"
|
|
78
78
|
}
|
|
@@ -159,8 +159,9 @@ function registerListBoxItem(loader, overrides) {
|
|
|
159
159
|
props: {
|
|
160
160
|
id: {
|
|
161
161
|
type: "string",
|
|
162
|
-
description: "
|
|
162
|
+
description: "A unique key for tracking the selected item in state",
|
|
163
163
|
required: true,
|
|
164
|
+
displayName: "Value",
|
|
164
165
|
validator: (_value, _props, ctx) => {
|
|
165
166
|
if (ctx == null ? void 0 : ctx.idError) {
|
|
166
167
|
return ctx.idError;
|
|
@@ -170,7 +171,8 @@ function registerListBoxItem(loader, overrides) {
|
|
|
170
171
|
},
|
|
171
172
|
textValue: {
|
|
172
173
|
type: "string",
|
|
173
|
-
|
|
174
|
+
displayName: "Label",
|
|
175
|
+
description: "A user-friendly text representation of the item's contents, used for features like typeahead."
|
|
174
176
|
},
|
|
175
177
|
children: {
|
|
176
178
|
type: "slot",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerListBoxItem.cjs.js","sources":["../src/registerListBoxItem.tsx"],"sourcesContent":["import { PlasmicElement } from \"@plasmicapp/host\";\nimport React, { useEffect, useState } from \"react\";\nimport { ListBox, ListBoxItem } from \"react-aria-components\";\nimport { PlasmicListBoxContext } from \"./contexts\";\nimport { DESCRIPTION_COMPONENT_NAME } from \"./registerDescription\";\nimport { TEXT_COMPONENT_NAME } from \"./registerText\";\nimport {\n CodeComponentMetaOverrides,\n HasControlContextData,\n makeComponentName,\n Registerable,\n registerComponentHelper,\n} from \"./utils\";\nimport { pickAriaComponentVariants, WithVariants } from \"./variant-utils\";\n\nconst LIST_BOX_ITEM_VARIANTS = [\n \"hovered\" as const,\n \"pressed\" as const,\n \"focused\" as const,\n \"focusVisible\" as const,\n \"selected\" as const,\n \"disabled\" as const,\n];\n\nconst { variants, withObservedValues } = pickAriaComponentVariants(\n LIST_BOX_ITEM_VARIANTS\n);\n\nexport interface BaseListBoxControlContextData {\n idError?: string;\n}\n\nexport interface BaseListBoxItemProps\n extends React.ComponentProps<typeof ListBoxItem>,\n HasControlContextData<BaseListBoxControlContextData>,\n WithVariants<typeof LIST_BOX_ITEM_VARIANTS> {\n id?: string;\n children?: React.ReactNode;\n}\n\nexport function BaseListBoxItem(props: BaseListBoxItemProps) {\n const { children, setControlContextData, plasmicUpdateVariant, id, ...rest } =\n props;\n const listboxContext = React.useContext(PlasmicListBoxContext);\n const isStandalone = !listboxContext;\n /**\n * Ids of each listboxitem inside a listbox have to be unique. Otherwise, the items won't show up in the listbox.\n * This is particularly important to ensure, because the most common use case would be to apply Repeat Element to the listbox item.\n * The ids of each repeated item will initially be the same (until the user changes the id prop of the listboxitem).\n *\n * The registerId, therefore, is the unique id of the listboxitem.\n * It is the id registered with the listbox context, so that it can auto-generate a unique id if it identifies a duplicate.\n */\n const [registeredId, setRegisteredId] = useState<string | undefined>();\n\n useEffect(() => {\n if (!listboxContext) {\n return;\n }\n\n const localId = listboxContext.idManager.register(id);\n setRegisteredId(localId);\n\n return () => {\n listboxContext.idManager.unregister(localId);\n setRegisteredId(undefined);\n };\n }, [id]);\n\n setControlContextData?.({\n idError: (() => {\n if (id === undefined) {\n return \"ID must be defined\";\n }\n if (typeof id !== \"string\") {\n return \"ID must be a string\";\n }\n if (!id.trim()) {\n return \"ID must be defined\";\n }\n if (!isStandalone && id != registeredId) {\n return \"ID must be unique\";\n }\n return undefined;\n })(),\n });\n\n const listboxItem = (\n <ListBoxItem key={registeredId} id={registeredId} {...rest}>\n {({\n isHovered,\n isPressed,\n isFocused,\n isFocusVisible,\n isSelected,\n isDisabled,\n }) =>\n withObservedValues(\n children,\n {\n hovered: isHovered,\n pressed: isPressed,\n focused: isFocused,\n focusVisible: isFocusVisible,\n selected: isSelected,\n disabled: isDisabled,\n },\n plasmicUpdateVariant\n )\n }\n </ListBoxItem>\n );\n\n if (isStandalone) {\n // selection mode needs to be single/multiple to be able to trigger hover state on it.\n return <ListBox selectionMode=\"single\">{listboxItem}</ListBox>;\n }\n\n return listboxItem;\n}\n\nexport const makeDefaultListBoxItemChildren = (\n label: string,\n description?: string\n): PlasmicElement => ({\n type: \"vbox\",\n styles: {\n display: \"flex\",\n alignItems: \"flex-start\",\n gap: \"2px\",\n },\n children: [\n {\n type: \"component\",\n name: TEXT_COMPONENT_NAME,\n props: {\n slot: \"label\",\n children: {\n type: \"text\",\n styles: {\n fontWeight: 500,\n },\n value: label,\n },\n },\n },\n {\n type: \"component\",\n name: DESCRIPTION_COMPONENT_NAME,\n props: {\n children: {\n type: \"text\",\n styles: {\n color: \"#838383\",\n },\n value: description ?? `Some description for ${label}...`,\n },\n },\n },\n ],\n});\n\nexport function registerListBoxItem(\n loader?: Registerable,\n overrides?: CodeComponentMetaOverrides<typeof BaseListBoxItem>\n) {\n return registerComponentHelper(\n loader,\n BaseListBoxItem,\n {\n name: makeComponentName(\"item\"),\n displayName: \"Aria ListBoxItem\",\n importPath: \"@plasmicpkgs/react-aria/skinny/registerListBoxItem\",\n importName: \"BaseListBoxItem\",\n variants,\n props: {\n id: {\n type: \"string\",\n description: \"
|
|
1
|
+
{"version":3,"file":"registerListBoxItem.cjs.js","sources":["../src/registerListBoxItem.tsx"],"sourcesContent":["import { PlasmicElement } from \"@plasmicapp/host\";\nimport React, { useEffect, useState } from \"react\";\nimport { ListBox, ListBoxItem } from \"react-aria-components\";\nimport { PlasmicListBoxContext } from \"./contexts\";\nimport { DESCRIPTION_COMPONENT_NAME } from \"./registerDescription\";\nimport { TEXT_COMPONENT_NAME } from \"./registerText\";\nimport {\n CodeComponentMetaOverrides,\n HasControlContextData,\n makeComponentName,\n Registerable,\n registerComponentHelper,\n} from \"./utils\";\nimport { pickAriaComponentVariants, WithVariants } from \"./variant-utils\";\n\nconst LIST_BOX_ITEM_VARIANTS = [\n \"hovered\" as const,\n \"pressed\" as const,\n \"focused\" as const,\n \"focusVisible\" as const,\n \"selected\" as const,\n \"disabled\" as const,\n];\n\nconst { variants, withObservedValues } = pickAriaComponentVariants(\n LIST_BOX_ITEM_VARIANTS\n);\n\nexport interface BaseListBoxControlContextData {\n idError?: string;\n}\n\nexport interface BaseListBoxItemProps\n extends React.ComponentProps<typeof ListBoxItem>,\n HasControlContextData<BaseListBoxControlContextData>,\n WithVariants<typeof LIST_BOX_ITEM_VARIANTS> {\n id?: string;\n children?: React.ReactNode;\n}\n\nexport function BaseListBoxItem(props: BaseListBoxItemProps) {\n const { children, setControlContextData, plasmicUpdateVariant, id, ...rest } =\n props;\n const listboxContext = React.useContext(PlasmicListBoxContext);\n const isStandalone = !listboxContext;\n /**\n * Ids of each listboxitem inside a listbox have to be unique. Otherwise, the items won't show up in the listbox.\n * This is particularly important to ensure, because the most common use case would be to apply Repeat Element to the listbox item.\n * The ids of each repeated item will initially be the same (until the user changes the id prop of the listboxitem).\n *\n * The registerId, therefore, is the unique id of the listboxitem.\n * It is the id registered with the listbox context, so that it can auto-generate a unique id if it identifies a duplicate.\n */\n const [registeredId, setRegisteredId] = useState<string | undefined>();\n\n useEffect(() => {\n if (!listboxContext) {\n return;\n }\n\n const localId = listboxContext.idManager.register(id);\n setRegisteredId(localId);\n\n return () => {\n listboxContext.idManager.unregister(localId);\n setRegisteredId(undefined);\n };\n }, [id]);\n\n setControlContextData?.({\n idError: (() => {\n if (id === undefined) {\n return \"ID must be defined\";\n }\n if (typeof id !== \"string\") {\n return \"ID must be a string\";\n }\n if (!id.trim()) {\n return \"ID must be defined\";\n }\n if (!isStandalone && id != registeredId) {\n return \"ID must be unique\";\n }\n return undefined;\n })(),\n });\n\n const listboxItem = (\n <ListBoxItem key={registeredId} id={registeredId} {...rest}>\n {({\n isHovered,\n isPressed,\n isFocused,\n isFocusVisible,\n isSelected,\n isDisabled,\n }) =>\n withObservedValues(\n children,\n {\n hovered: isHovered,\n pressed: isPressed,\n focused: isFocused,\n focusVisible: isFocusVisible,\n selected: isSelected,\n disabled: isDisabled,\n },\n plasmicUpdateVariant\n )\n }\n </ListBoxItem>\n );\n\n if (isStandalone) {\n // selection mode needs to be single/multiple to be able to trigger hover state on it.\n return <ListBox selectionMode=\"single\">{listboxItem}</ListBox>;\n }\n\n return listboxItem;\n}\n\nexport const makeDefaultListBoxItemChildren = (\n label: string,\n description?: string\n): PlasmicElement => ({\n type: \"vbox\",\n styles: {\n display: \"flex\",\n alignItems: \"flex-start\",\n gap: \"2px\",\n },\n children: [\n {\n type: \"component\",\n name: TEXT_COMPONENT_NAME,\n props: {\n slot: \"label\",\n children: {\n type: \"text\",\n styles: {\n fontWeight: 500,\n },\n value: label,\n },\n },\n },\n {\n type: \"component\",\n name: DESCRIPTION_COMPONENT_NAME,\n props: {\n children: {\n type: \"text\",\n styles: {\n color: \"#838383\",\n },\n value: description ?? `Some description for ${label}...`,\n },\n },\n },\n ],\n});\n\nexport function registerListBoxItem(\n loader?: Registerable,\n overrides?: CodeComponentMetaOverrides<typeof BaseListBoxItem>\n) {\n return registerComponentHelper(\n loader,\n BaseListBoxItem,\n {\n name: makeComponentName(\"item\"),\n displayName: \"Aria ListBoxItem\",\n importPath: \"@plasmicpkgs/react-aria/skinny/registerListBoxItem\",\n importName: \"BaseListBoxItem\",\n variants,\n props: {\n id: {\n type: \"string\",\n description: \"A unique key for tracking the selected item in state\",\n required: true,\n displayName: \"Value\",\n validator: (_value, _props, ctx) => {\n if (ctx?.idError) {\n return ctx.idError;\n }\n return true;\n },\n },\n textValue: {\n type: \"string\",\n displayName: \"Label\",\n description:\n \"A user-friendly text representation of the item's contents, used for features like typeahead.\",\n },\n children: {\n type: \"slot\",\n mergeWithParent: true,\n defaultValue: makeDefaultListBoxItemChildren(\"Item\"),\n },\n },\n trapsFocus: true,\n },\n overrides\n );\n}\n"],"names":["pickAriaComponentVariants","React","PlasmicListBoxContext","useState","useEffect","ListBoxItem","ListBox","TEXT_COMPONENT_NAME","DESCRIPTION_COMPONENT_NAME","registerComponentHelper","makeComponentName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,sBAAyB,GAAA;AAAA,EAC7B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AACF,CAAA,CAAA;AAEA,MAAM,EAAE,QAAU,EAAA,kBAAA,EAAuB,GAAAA,sCAAA;AAAA,EACvC,sBAAA;AACF,CAAA,CAAA;AAcO,SAAS,gBAAgB,KAA6B,EAAA;AAC3D,EAAA,MACE,EADM,GAAA,KAAA,EAAA,EAAA,QAAA,EAAU,qBAAuB,EAAA,oBAAA,EAAsB,EAzCjE,EAAA,GA0CI,EADoE,EAAA,IAAA,GAAA,SAAA,CACpE,EADoE,EAAA,CAA9D,UAAU,EAAA,uBAAA,EAAuB,sBAAsB,EAAA,IAAA,CAAA,CAAA,CAA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,IACA,SAAA;AAAA,GACF,CAAA;AACF;;;;;;"}
|
|
@@ -153,8 +153,9 @@ function registerListBoxItem(loader, overrides) {
|
|
|
153
153
|
props: {
|
|
154
154
|
id: {
|
|
155
155
|
type: "string",
|
|
156
|
-
description: "
|
|
156
|
+
description: "A unique key for tracking the selected item in state",
|
|
157
157
|
required: true,
|
|
158
|
+
displayName: "Value",
|
|
158
159
|
validator: (_value, _props, ctx) => {
|
|
159
160
|
if (ctx == null ? void 0 : ctx.idError) {
|
|
160
161
|
return ctx.idError;
|
|
@@ -164,7 +165,8 @@ function registerListBoxItem(loader, overrides) {
|
|
|
164
165
|
},
|
|
165
166
|
textValue: {
|
|
166
167
|
type: "string",
|
|
167
|
-
|
|
168
|
+
displayName: "Label",
|
|
169
|
+
description: "A user-friendly text representation of the item's contents, used for features like typeahead."
|
|
168
170
|
},
|
|
169
171
|
children: {
|
|
170
172
|
type: "slot",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerListBoxItem.esm.js","sources":["../src/registerListBoxItem.tsx"],"sourcesContent":["import { PlasmicElement } from \"@plasmicapp/host\";\nimport React, { useEffect, useState } from \"react\";\nimport { ListBox, ListBoxItem } from \"react-aria-components\";\nimport { PlasmicListBoxContext } from \"./contexts\";\nimport { DESCRIPTION_COMPONENT_NAME } from \"./registerDescription\";\nimport { TEXT_COMPONENT_NAME } from \"./registerText\";\nimport {\n CodeComponentMetaOverrides,\n HasControlContextData,\n makeComponentName,\n Registerable,\n registerComponentHelper,\n} from \"./utils\";\nimport { pickAriaComponentVariants, WithVariants } from \"./variant-utils\";\n\nconst LIST_BOX_ITEM_VARIANTS = [\n \"hovered\" as const,\n \"pressed\" as const,\n \"focused\" as const,\n \"focusVisible\" as const,\n \"selected\" as const,\n \"disabled\" as const,\n];\n\nconst { variants, withObservedValues } = pickAriaComponentVariants(\n LIST_BOX_ITEM_VARIANTS\n);\n\nexport interface BaseListBoxControlContextData {\n idError?: string;\n}\n\nexport interface BaseListBoxItemProps\n extends React.ComponentProps<typeof ListBoxItem>,\n HasControlContextData<BaseListBoxControlContextData>,\n WithVariants<typeof LIST_BOX_ITEM_VARIANTS> {\n id?: string;\n children?: React.ReactNode;\n}\n\nexport function BaseListBoxItem(props: BaseListBoxItemProps) {\n const { children, setControlContextData, plasmicUpdateVariant, id, ...rest } =\n props;\n const listboxContext = React.useContext(PlasmicListBoxContext);\n const isStandalone = !listboxContext;\n /**\n * Ids of each listboxitem inside a listbox have to be unique. Otherwise, the items won't show up in the listbox.\n * This is particularly important to ensure, because the most common use case would be to apply Repeat Element to the listbox item.\n * The ids of each repeated item will initially be the same (until the user changes the id prop of the listboxitem).\n *\n * The registerId, therefore, is the unique id of the listboxitem.\n * It is the id registered with the listbox context, so that it can auto-generate a unique id if it identifies a duplicate.\n */\n const [registeredId, setRegisteredId] = useState<string | undefined>();\n\n useEffect(() => {\n if (!listboxContext) {\n return;\n }\n\n const localId = listboxContext.idManager.register(id);\n setRegisteredId(localId);\n\n return () => {\n listboxContext.idManager.unregister(localId);\n setRegisteredId(undefined);\n };\n }, [id]);\n\n setControlContextData?.({\n idError: (() => {\n if (id === undefined) {\n return \"ID must be defined\";\n }\n if (typeof id !== \"string\") {\n return \"ID must be a string\";\n }\n if (!id.trim()) {\n return \"ID must be defined\";\n }\n if (!isStandalone && id != registeredId) {\n return \"ID must be unique\";\n }\n return undefined;\n })(),\n });\n\n const listboxItem = (\n <ListBoxItem key={registeredId} id={registeredId} {...rest}>\n {({\n isHovered,\n isPressed,\n isFocused,\n isFocusVisible,\n isSelected,\n isDisabled,\n }) =>\n withObservedValues(\n children,\n {\n hovered: isHovered,\n pressed: isPressed,\n focused: isFocused,\n focusVisible: isFocusVisible,\n selected: isSelected,\n disabled: isDisabled,\n },\n plasmicUpdateVariant\n )\n }\n </ListBoxItem>\n );\n\n if (isStandalone) {\n // selection mode needs to be single/multiple to be able to trigger hover state on it.\n return <ListBox selectionMode=\"single\">{listboxItem}</ListBox>;\n }\n\n return listboxItem;\n}\n\nexport const makeDefaultListBoxItemChildren = (\n label: string,\n description?: string\n): PlasmicElement => ({\n type: \"vbox\",\n styles: {\n display: \"flex\",\n alignItems: \"flex-start\",\n gap: \"2px\",\n },\n children: [\n {\n type: \"component\",\n name: TEXT_COMPONENT_NAME,\n props: {\n slot: \"label\",\n children: {\n type: \"text\",\n styles: {\n fontWeight: 500,\n },\n value: label,\n },\n },\n },\n {\n type: \"component\",\n name: DESCRIPTION_COMPONENT_NAME,\n props: {\n children: {\n type: \"text\",\n styles: {\n color: \"#838383\",\n },\n value: description ?? `Some description for ${label}...`,\n },\n },\n },\n ],\n});\n\nexport function registerListBoxItem(\n loader?: Registerable,\n overrides?: CodeComponentMetaOverrides<typeof BaseListBoxItem>\n) {\n return registerComponentHelper(\n loader,\n BaseListBoxItem,\n {\n name: makeComponentName(\"item\"),\n displayName: \"Aria ListBoxItem\",\n importPath: \"@plasmicpkgs/react-aria/skinny/registerListBoxItem\",\n importName: \"BaseListBoxItem\",\n variants,\n props: {\n id: {\n type: \"string\",\n description: \"
|
|
1
|
+
{"version":3,"file":"registerListBoxItem.esm.js","sources":["../src/registerListBoxItem.tsx"],"sourcesContent":["import { PlasmicElement } from \"@plasmicapp/host\";\nimport React, { useEffect, useState } from \"react\";\nimport { ListBox, ListBoxItem } from \"react-aria-components\";\nimport { PlasmicListBoxContext } from \"./contexts\";\nimport { DESCRIPTION_COMPONENT_NAME } from \"./registerDescription\";\nimport { TEXT_COMPONENT_NAME } from \"./registerText\";\nimport {\n CodeComponentMetaOverrides,\n HasControlContextData,\n makeComponentName,\n Registerable,\n registerComponentHelper,\n} from \"./utils\";\nimport { pickAriaComponentVariants, WithVariants } from \"./variant-utils\";\n\nconst LIST_BOX_ITEM_VARIANTS = [\n \"hovered\" as const,\n \"pressed\" as const,\n \"focused\" as const,\n \"focusVisible\" as const,\n \"selected\" as const,\n \"disabled\" as const,\n];\n\nconst { variants, withObservedValues } = pickAriaComponentVariants(\n LIST_BOX_ITEM_VARIANTS\n);\n\nexport interface BaseListBoxControlContextData {\n idError?: string;\n}\n\nexport interface BaseListBoxItemProps\n extends React.ComponentProps<typeof ListBoxItem>,\n HasControlContextData<BaseListBoxControlContextData>,\n WithVariants<typeof LIST_BOX_ITEM_VARIANTS> {\n id?: string;\n children?: React.ReactNode;\n}\n\nexport function BaseListBoxItem(props: BaseListBoxItemProps) {\n const { children, setControlContextData, plasmicUpdateVariant, id, ...rest } =\n props;\n const listboxContext = React.useContext(PlasmicListBoxContext);\n const isStandalone = !listboxContext;\n /**\n * Ids of each listboxitem inside a listbox have to be unique. Otherwise, the items won't show up in the listbox.\n * This is particularly important to ensure, because the most common use case would be to apply Repeat Element to the listbox item.\n * The ids of each repeated item will initially be the same (until the user changes the id prop of the listboxitem).\n *\n * The registerId, therefore, is the unique id of the listboxitem.\n * It is the id registered with the listbox context, so that it can auto-generate a unique id if it identifies a duplicate.\n */\n const [registeredId, setRegisteredId] = useState<string | undefined>();\n\n useEffect(() => {\n if (!listboxContext) {\n return;\n }\n\n const localId = listboxContext.idManager.register(id);\n setRegisteredId(localId);\n\n return () => {\n listboxContext.idManager.unregister(localId);\n setRegisteredId(undefined);\n };\n }, [id]);\n\n setControlContextData?.({\n idError: (() => {\n if (id === undefined) {\n return \"ID must be defined\";\n }\n if (typeof id !== \"string\") {\n return \"ID must be a string\";\n }\n if (!id.trim()) {\n return \"ID must be defined\";\n }\n if (!isStandalone && id != registeredId) {\n return \"ID must be unique\";\n }\n return undefined;\n })(),\n });\n\n const listboxItem = (\n <ListBoxItem key={registeredId} id={registeredId} {...rest}>\n {({\n isHovered,\n isPressed,\n isFocused,\n isFocusVisible,\n isSelected,\n isDisabled,\n }) =>\n withObservedValues(\n children,\n {\n hovered: isHovered,\n pressed: isPressed,\n focused: isFocused,\n focusVisible: isFocusVisible,\n selected: isSelected,\n disabled: isDisabled,\n },\n plasmicUpdateVariant\n )\n }\n </ListBoxItem>\n );\n\n if (isStandalone) {\n // selection mode needs to be single/multiple to be able to trigger hover state on it.\n return <ListBox selectionMode=\"single\">{listboxItem}</ListBox>;\n }\n\n return listboxItem;\n}\n\nexport const makeDefaultListBoxItemChildren = (\n label: string,\n description?: string\n): PlasmicElement => ({\n type: \"vbox\",\n styles: {\n display: \"flex\",\n alignItems: \"flex-start\",\n gap: \"2px\",\n },\n children: [\n {\n type: \"component\",\n name: TEXT_COMPONENT_NAME,\n props: {\n slot: \"label\",\n children: {\n type: \"text\",\n styles: {\n fontWeight: 500,\n },\n value: label,\n },\n },\n },\n {\n type: \"component\",\n name: DESCRIPTION_COMPONENT_NAME,\n props: {\n children: {\n type: \"text\",\n styles: {\n color: \"#838383\",\n },\n value: description ?? `Some description for ${label}...`,\n },\n },\n },\n ],\n});\n\nexport function registerListBoxItem(\n loader?: Registerable,\n overrides?: CodeComponentMetaOverrides<typeof BaseListBoxItem>\n) {\n return registerComponentHelper(\n loader,\n BaseListBoxItem,\n {\n name: makeComponentName(\"item\"),\n displayName: \"Aria ListBoxItem\",\n importPath: \"@plasmicpkgs/react-aria/skinny/registerListBoxItem\",\n importName: \"BaseListBoxItem\",\n variants,\n props: {\n id: {\n type: \"string\",\n description: \"A unique key for tracking the selected item in state\",\n required: true,\n displayName: \"Value\",\n validator: (_value, _props, ctx) => {\n if (ctx?.idError) {\n return ctx.idError;\n }\n return true;\n },\n },\n textValue: {\n type: \"string\",\n displayName: \"Label\",\n description:\n \"A user-friendly text representation of the item's contents, used for features like typeahead.\",\n },\n children: {\n type: \"slot\",\n mergeWithParent: true,\n defaultValue: makeDefaultListBoxItemChildren(\"Item\"),\n },\n },\n trapsFocus: true,\n },\n overrides\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,sBAAyB,GAAA;AAAA,EAC7B,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AACF,CAAA,CAAA;AAEA,MAAM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