@@ -178,6 +178,8 @@ const optionLabelKeys: Readonly<Record<string, MessageKey>> = {
178178 default : "detail.option.default" ,
179179 replacing : "detail.option.replacing" ,
180180 disabled : "detail.option.disabled" ,
181+ filled : "detail.option.filled" ,
182+ "read-only" : "detail.option.read-only" ,
181183 display : "detail.option.display" ,
182184 error : "detail.option.error" ,
183185 expanded : "detail.option.expanded" ,
@@ -298,6 +300,27 @@ function NumberInputPreview({ state }: { state: string }) {
298300 ) ;
299301}
300302
303+ function SearchFieldStatePreview ( { state } : { state : string } ) {
304+ const { t } = useI18n ( ) ;
305+ const [ value , setValue ] = useState ( state === "default" ? "" : "OpenBitFun" ) ;
306+ return (
307+ < SearchField
308+ aria-label = { t ( "components.preview.searchLabel" ) }
309+ className = { state === "hover" ? "lab-force-hover" : state === "focus-visible" ? "lab-force-focus" : undefined }
310+ clearLabel = { t ( "components.preview.searchClear" ) }
311+ disabled = { state === "disabled" }
312+ invalid = { state === "invalid" }
313+ leadingIcon = { < Icon name = "search" /> }
314+ onClear = { ( ) => setValue ( "" ) }
315+ onValueChange = { setValue }
316+ placeholder = { t ( "components.preview.searchPlaceholder" ) }
317+ readOnly = { state === "read-only" }
318+ shortcut = { < KeyHint icon = { < Icon name = "command-mac" /> } > K</ KeyHint > }
319+ value = { value }
320+ />
321+ ) ;
322+ }
323+
301324export function ComponentDetailPage ( {
302325 colorScheme,
303326 component,
@@ -399,7 +422,7 @@ export function ComponentDetailPage({
399422 return [ "raised" , "subtle" , "media" ] as const ;
400423 case "Input" :
401424 case "SearchField" :
402- return [ "default" , "hover" , "focus-visible" , "invalid" , "disabled" ] as const ;
425+ return [ "default" , "filled" , " hover", "focus-visible" , "read-only ", "invalid" , "disabled" ] as const ;
403426 case "Select" :
404427 return [ "default" , "hover" , "focus-visible" , "open" , "invalid" , "disabled" ] as const ;
405428 case "Field" :
@@ -541,7 +564,9 @@ export function ComponentDetailPage({
541564 ? " disabled"
542565 : previewState === "invalid"
543566 ? " invalid"
544- : "" ;
567+ : previewState === "read-only"
568+ ? ' readOnly defaultValue="OpenBitFun"'
569+ : previewState === "default" ? "" : ' defaultValue="OpenBitFun"' ;
545570 return `import { Icon, Input } from "@openbitfun/ui";\n\n<Input\n aria-label="${ t ( "components.preview.inputLabel" ) } "\n placeholder="${ t ( "components.preview.inputPlaceholder" ) } "\n trailing={<Icon name="eye" />}${ stateProps } \n/>` ;
546571 }
547572 if ( component . name === "KeyHint" ) {
@@ -570,12 +595,8 @@ export function ComponentDetailPage({
570595 return `import { Icon, IconButton, PageHeader } from "@openbitfun/ui";\n\n<PageHeader\n action={<IconButton aria-label="${ t ( "components.preview.close" ) } " icon={<Icon name="xmark" />} />}\n align="${ pageHeaderAlign } "\n description="${ t ( "components.preview.appearanceDescription" ) } "\n leading={<Icon name="gear" />}\n level={2}${ requiredProp } \n size="${ pageHeaderSize } "\n title="${ t ( "components.preview.appearance" ) } "\n/>` ;
571596 }
572597 if ( component . name === "SearchField" ) {
573- const stateProps = previewState === "disabled"
574- ? " disabled"
575- : previewState === "invalid"
576- ? " invalid"
577- : "" ;
578- return `import { Icon, KeyHint, SearchField } from "@openbitfun/ui";\n\n<SearchField\n aria-label="${ t ( "components.preview.searchLabel" ) } "\n leadingIcon={<Icon name="search" />}\n placeholder="${ t ( "components.preview.searchPlaceholder" ) } "\n shortcut={<KeyHint icon={<Icon name="command-mac" />}>K</KeyHint>}${ stateProps } \n/>` ;
598+ const searchStateProps = previewState === "disabled" ? " disabled" : previewState === "invalid" ? " invalid" : previewState === "read-only" ? " readOnly" : "" ;
599+ return `import { useState } from "react";\nimport { Icon, KeyHint, SearchField } from "@openbitfun/ui";\n\nfunction Example() {\n const [query, setQuery] = useState(${ JSON . stringify ( previewState === "default" ? "" : "OpenBitFun" ) } );\n return (\n <SearchField\n clearLabel="${ t ( "components.preview.searchClear" ) } "\n onClear={() => setQuery("")}\n onValueChange={setQuery}\n value={query}\n aria-label="${ t ( "components.preview.searchLabel" ) } "\n leadingIcon={<Icon name="search" />}\n placeholder="${ t ( "components.preview.searchPlaceholder" ) } "\n shortcut={<KeyHint icon={<Icon name="command-mac" />}>K</KeyHint>}${ searchStateProps } \n />\n );\n}` ;
579600 }
580601 if ( component . name === "Combobox" ) {
581602 return `import { Combobox } from "@openbitfun/ui";\n\n<Combobox\n aria-label="Mode"\n onValueChange={setMode}\n options={[\n { label: "Ask", value: "ask" },\n { label: "Plan", value: "plan" },\n { disabled: true, label: "Agent", value: "agent" },\n ]}\n value={mode}\n/>` ;
@@ -1327,10 +1348,13 @@ export function ComponentDetailPage({
13271348 < Input
13281349 aria-label = { t ( "components.preview.inputLabel" ) }
13291350 className = { previewClassName }
1351+ defaultValue = { state === "default" ? undefined : "OpenBitFun" }
1352+ key = { state }
13301353 disabled = { state === "disabled" }
13311354 invalid = { state === "invalid" }
13321355 placeholder = { t ( "components.preview.inputPlaceholder" ) }
1333- trailing = { < Icon name = "eye" size = "lg" aria-hidden = "true" /> }
1356+ readOnly = { state === "read-only" }
1357+ trailing = { < Icon name = "eye" /> }
13341358 />
13351359 ) ;
13361360 }
@@ -1775,22 +1799,7 @@ export function ComponentDetailPage({
17751799 }
17761800
17771801 if ( component . name === "SearchField" ) {
1778- const previewClassName = state === "hover"
1779- ? "lab-force-hover"
1780- : state === "focus-visible"
1781- ? "lab-force-focus"
1782- : undefined ;
1783- return (
1784- < SearchField
1785- aria-label = { t ( "components.preview.searchLabel" ) }
1786- className = { previewClassName }
1787- disabled = { state === "disabled" }
1788- invalid = { state === "invalid" }
1789- leadingIcon = { < Icon name = "search" size = "lg" aria-hidden = "true" /> }
1790- placeholder = { t ( "components.preview.searchPlaceholder" ) }
1791- shortcut = { < KeyHint icon = { < Icon name = "command-mac" size = "lg" aria-hidden = "true" /> } > K</ KeyHint > }
1792- />
1793- ) ;
1802+ return < SearchFieldStatePreview key = { state } state = { state } /> ;
17941803 }
17951804
17961805 if ( component . name === "NavigationPanel" ) {
0 commit comments