@madebywild/sanity-icon-field 0.3.14 → 0.3.16
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/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/types.tsx +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction defaultRenderSelected(value: string) {\n return <Text size={2}>{value}</Text>;\n}\n\nfunction defaultRenderOption({ label, value }: { label?: string; value: string }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = pluginConfig.iconList;\n const renderOption = pluginConfig.renderOption ?? defaultRenderOption;\n const renderSelected = pluginConfig.renderSelected ?? defaultRenderSelected;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n whitelist={whitelist}\n blacklist={blacklist}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n return renderSelected(value);\n }}\n renderOption={({ label, value }) => {\n return renderOption({ label, value });\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { ObjectOptions, StringDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of icons to show in the icon picker.\n * @example\n * ```ts\n * iconList: [\n * { label: \"X\", value: \"x\" },\n * { label: \"Check\", value: \"check\" },\n * ]\n * ```\n */\n iconList: ListItems;\n /**\n * A function to render the selected icon value.\n * @example\n * ```ts\n * renderSelected: (value) => <svg><use href={`#icon-${value}`} /></svg>\n * ```\n */\n renderSelected?: (value: string) => React.JSX.Element;\n /** A function to render each icon option in the dropdown.\n * @example\n * ```ts\n * renderOption: (item) => <div>{item.label}</div>\n * ```\n */\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whitelist icons by their values.\n */\n whitelist?: string[];\n /**\n * Blacklist icons by their values.\n */\n blacklist?: string[];\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["defaultRenderSelected","value","jsx","Text","defaultRenderOption","label","Card","Flex","Box","IconInput","t0","$","_c","pluginConfig","props","options","schemaType","iconList","renderOption","renderSelected","whitelist","blacklist","t1","value_0","next","set","unset","onChange","t2","value_1","t3","t4","value_2","AsyncAutocomplete","_temp","opt","typeName","wildSanityIconFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","Fragment","components","input"],"mappings":";;;AAKA,SAASA,sBAAsBC,OAAe;AAC5C,SAAOC,2BAAAA,IAACC,GAAAA,MAAA,EAAK,MAAM,GAAIF,UAAAA,OAAM;AAC/B;AAEA,SAASG,oBAAoB;AAAA,EAAEC;AAAAA,EAAOJ;AAAyC,GAAG;AAChF,SACEC,2BAAAA,IAACI,GAAAA,QAAK,IAAG,UACP,0CAACC,GAAAA,MAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,IAAAL,2BAAAA,IAAC,UAAK,UAAA,YAAA,CAAE;AAAA,IACRA,2BAAAA,IAACM,GAAAA,KAAA,EAAI,MAAM,GAAG,SAAS,GACrB,UAAAN,2BAAAA,IAACC,GAAAA,MAAA,EAAK,MAAM,GAAIE,UAAAA,SAASJ,MAAAA,CAAM,EAAA,CACjC;AAAA,EAAA,EAAA,CACF,EAAA,CACF;AAEJ;AAEA,SAAAQ,UAAAC,IAAA;AAAA,QAAAC,IAAAC,gBAAAA,EAAA,EAAA;AAAA,MAAAC,cAAAC;AAAAH,WAAAD,MAAmB;AAAA,IAAAG;AAAAA,IAAA,GAAAC;AAAAA,EAAAA,IAAAJ,IAKlBC,OAAAD,IAAAC,OAAAE,cAAAF,OAAAG,UAAAD,eAAAF,EAAA,CAAA,GAAAG,QAAAH,EAAA,CAAA;AACC,QAAAI,UAAgBD,MAAKE,WAAWD,SAChCE,WAAiBJ,aAAYI,UAC7BC,eAAqBL,aAAYK,gBAAZd,qBACrBe,iBAAuBN,aAAYM,kBAAZnB,uBAEvBoB,YAAkBL,SAAOK,WACzBC,YAAkBN,SAAOM;AAAY,MAAAC;A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jC,OAAAkC,KAAA;AAAA,SAsBmCA,KAAG9B,SAAHJ;AAAmB;ACxC/C,MAAMmC,WAAW,aCClBC,4BAA4BC,OAAAA,aAA4BC,CAAAA,YACrD;AAAA,EACLC,MAAM;AAAA,EACNC,QAAQ;AAAA,IACNC,OAAO,CACLC,OAAAA,WAAW;AAAA,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM7C,2BAAAA,IAAA8C,WAAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQpC,CAAAA,UAAUZ,+BAAC,aAAU,cAAcqC,QAAQ,GAAIzB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction defaultRenderSelected(value: string) {\n return <Text size={2}>{value}</Text>;\n}\n\nfunction defaultRenderOption({ label, value }: { label?: string; value: string }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = pluginConfig.iconList;\n const renderOption = pluginConfig.renderOption ?? defaultRenderOption;\n const renderSelected = pluginConfig.renderSelected ?? defaultRenderSelected;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n whitelist={whitelist}\n blacklist={blacklist}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n return renderSelected(value);\n }}\n renderOption={({ label, value }) => {\n return renderOption({ label, value });\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { ObjectOptions, StringDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of icons to show in the icon picker.\n * @example\n * ```ts\n * iconList: [\n * { label: \"X\", value: \"x\" },\n * { label: \"Check\", value: \"check\" },\n * ]\n * ```\n */\n iconList: ListItems;\n /**\n * A function to render the selected icon value.\n * @example\n * ```ts\n * renderSelected: (value) => <svg><use href={`#icon-${value}`} /></svg>\n * ```\n */\n renderSelected?: (value: string) => React.JSX.Element;\n /** A function to render each icon option in the dropdown.\n * @example\n * ```ts\n * renderOption: (item) => <div>{item.label}</div>\n * ```\n */\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whitelist icons by their values.\n */\n whitelist?: string[];\n /**\n * Blacklist icons by their values.\n */\n blacklist?: string[];\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\" | \"components\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["defaultRenderSelected","value","jsx","Text","defaultRenderOption","label","Card","Flex","Box","IconInput","t0","$","_c","pluginConfig","props","options","schemaType","iconList","renderOption","renderSelected","whitelist","blacklist","t1","value_0","next","set","unset","onChange","t2","value_1","t3","t4","value_2","AsyncAutocomplete","_temp","opt","typeName","wildSanityIconFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","Fragment","components","input"],"mappings":";;;AAKA,SAASA,sBAAsBC,OAAe;AAC5C,SAAOC,2BAAAA,IAACC,GAAAA,MAAA,EAAK,MAAM,GAAIF,UAAAA,OAAM;AAC/B;AAEA,SAASG,oBAAoB;AAAA,EAAEC;AAAAA,EAAOJ;AAAyC,GAAG;AAChF,SACEC,2BAAAA,IAACI,GAAAA,QAAK,IAAG,UACP,0CAACC,GAAAA,MAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,IAAAL,2BAAAA,IAAC,UAAK,UAAA,YAAA,CAAE;AAAA,IACRA,2BAAAA,IAACM,GAAAA,KAAA,EAAI,MAAM,GAAG,SAAS,GACrB,UAAAN,2BAAAA,IAACC,GAAAA,MAAA,EAAK,MAAM,GAAIE,UAAAA,SAASJ,MAAAA,CAAM,EAAA,CACjC;AAAA,EAAA,EAAA,CACF,EAAA,CACF;AAEJ;AAEA,SAAAQ,UAAAC,IAAA;AAAA,QAAAC,IAAAC,gBAAAA,EAAA,EAAA;AAAA,MAAAC,cAAAC;AAAAH,WAAAD,MAAmB;AAAA,IAAAG;AAAAA,IAAA,GAAAC;AAAAA,EAAAA,IAAAJ,IAKlBC,OAAAD,IAAAC,OAAAE,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OACH,UAAAZ,IAIM,gBAAAM,IAGF,cAAAE,GAAAA,CAEb,GACDnB,OAAAU,WAAAV,QAAAM,UAAAN,EAAA,EAAA,IAAAG,MAAAb,OAAAU,QAAAW,IAAAX,QAAAiB,IAAAjB,QAAAmB,IAAAnB,QAAAS,WAAAT,QAAAoB,MAAAA,KAAApB,EAAA,EAAA,GAlBFoB;AAkBE;AAjCN,SAAAG,MAAAjC,OAAAkC,KAAA;AAAA,SAsBmCA,KAAG9B,SAAHJ;AAAmB;ACxC/C,MAAMmC,WAAW,aCClBC,4BAA4BC,OAAAA,aAA4BC,CAAAA,YACrD;AAAA,EACLC,MAAM;AAAA,EACNC,QAAQ;AAAA,IACNC,OAAO,CACLC,OAAAA,WAAW;AAAA,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM7C,2BAAAA,IAAA8C,WAAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQpC,CAAAA,UAAUZ,+BAAC,aAAU,cAAcqC,QAAQ,GAAIzB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -55,7 +55,7 @@ type FieldOptions = ObjectOptions & {
|
|
|
55
55
|
};
|
|
56
56
|
declare module "sanity" {
|
|
57
57
|
interface IntrinsicDefinitions {
|
|
58
|
-
[typeName]: Omit<StringDefinition, "type" | "fields" | "options"> & {
|
|
58
|
+
[typeName]: Omit<StringDefinition, "type" | "fields" | "options" | "components"> & {
|
|
59
59
|
type: typeof typeName;
|
|
60
60
|
options?: FieldOptions;
|
|
61
61
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ type FieldOptions = ObjectOptions & {
|
|
|
55
55
|
};
|
|
56
56
|
declare module "sanity" {
|
|
57
57
|
interface IntrinsicDefinitions {
|
|
58
|
-
[typeName]: Omit<StringDefinition, "type" | "fields" | "options"> & {
|
|
58
|
+
[typeName]: Omit<StringDefinition, "type" | "fields" | "options" | "components"> & {
|
|
59
59
|
type: typeof typeName;
|
|
60
60
|
options?: FieldOptions;
|
|
61
61
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction defaultRenderSelected(value: string) {\n return <Text size={2}>{value}</Text>;\n}\n\nfunction defaultRenderOption({ label, value }: { label?: string; value: string }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = pluginConfig.iconList;\n const renderOption = pluginConfig.renderOption ?? defaultRenderOption;\n const renderSelected = pluginConfig.renderSelected ?? defaultRenderSelected;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n whitelist={whitelist}\n blacklist={blacklist}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n return renderSelected(value);\n }}\n renderOption={({ label, value }) => {\n return renderOption({ label, value });\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { ObjectOptions, StringDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of icons to show in the icon picker.\n * @example\n * ```ts\n * iconList: [\n * { label: \"X\", value: \"x\" },\n * { label: \"Check\", value: \"check\" },\n * ]\n * ```\n */\n iconList: ListItems;\n /**\n * A function to render the selected icon value.\n * @example\n * ```ts\n * renderSelected: (value) => <svg><use href={`#icon-${value}`} /></svg>\n * ```\n */\n renderSelected?: (value: string) => React.JSX.Element;\n /** A function to render each icon option in the dropdown.\n * @example\n * ```ts\n * renderOption: (item) => <div>{item.label}</div>\n * ```\n */\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whitelist icons by their values.\n */\n whitelist?: string[];\n /**\n * Blacklist icons by their values.\n */\n blacklist?: string[];\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["defaultRenderSelected","value","defaultRenderOption","label","IconInput","t0","$","_c","pluginConfig","props","options","schemaType","iconList","renderOption","renderSelected","whitelist","blacklist","t1","value_0","next","set","unset","onChange","t2","value_1","t3","t4","value_2","_temp","opt","typeName","wildSanityIconFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","components","input"],"mappings":";;;;;AAKA,SAASA,sBAAsBC,OAAe;AAC5C,SAAO,oBAAC,MAAA,EAAK,MAAM,GAAIA,UAAAA,OAAM;AAC/B;AAEA,SAASC,oBAAoB;AAAA,EAAEC;AAAAA,EAAOF;AAAyC,GAAG;AAChF,SACE,oBAAC,QAAK,IAAG,UACP,+BAAC,MAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,IAAA,oBAAC,UAAK,UAAA,YAAA,CAAE;AAAA,IACR,oBAAC,KAAA,EAAI,MAAM,GAAG,SAAS,GACrB,UAAA,oBAAC,MAAA,EAAK,MAAM,GAAIE,UAAAA,SAASF,MAAAA,CAAM,EAAA,CACjC;AAAA,EAAA,EAAA,CACF,EAAA,CACF;AAEJ;AAEA,SAAAG,UAAAC,IAAA;AAAA,QAAAC,IAAAC,EAAA,EAAA;AAAA,MAAAC,cAAAC;AAAAH,WAAAD,MAAmB;AAAA,IAAAG;AAAAA,IAAA,GAAAC;AAAAA,EAAAA,IAAAJ,IAKlBC,OAAAD,IAAAC,OAAAE,cAAAF,OAAAG,UAAAD,eAAAF,EAAA,CAAA,GAAAG,QAAAH,EAAA,CAAA;AACC,QAAAI,UAAgBD,MAAKE,WAAWD,SAChCE,WAAiBJ,aAAYI,UAC7BC,eAAqBL,aAAYK,gBAAZX,qBACrBY,iBAAuBN,aAAYM,kBAAZd,uBAEvBe,YAAkBL,SAAOK,WACzBC,YAAkBN,SAAOM;AAAY,MAAAC;AAAAX,WAAAG,SAWvBQ,KAAAC,CAAAA,YAAA;AACR,UAAAC,OAAalB,UAAQmB,IAAInB,OAAe,IAANoB,MAAAA;AAAQ,WACnCZ,MAAKa,SAAUH,IAAI;AAAA,EAAC,GAC5Bb,OAAAG,OAAAH,OAAAW,MAAAA,KAAAX,E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NC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM,oBAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQlC,CAAAA,UAAU,oBAAC,aAAU,cAAcwB,QAAQ,GAAIxB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/input.tsx","../src/types.tsx","../src/index.tsx"],"sourcesContent":["import { AsyncAutocomplete } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport { Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\nfunction defaultRenderSelected(value: string) {\n return <Text size={2}>{value}</Text>;\n}\n\nfunction defaultRenderOption({ label, value }: { label?: string; value: string }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n <span>🧿</span>\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction IconInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const iconList = pluginConfig.iconList;\n const renderOption = pluginConfig.renderOption ?? defaultRenderOption;\n const renderSelected = pluginConfig.renderSelected ?? defaultRenderSelected;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select icon\"\n noOptionsPlaceholder=\"No icons found\"\n listItems={iconList}\n whitelist={whitelist}\n blacklist={blacklist}\n value={props.value}\n renderValue={(value, opt) => opt?.label ?? value}\n onChange={(value) => {\n const next = value ? set(value) : unset();\n return props.onChange(next);\n }}\n renderSelected={(value) => {\n return renderSelected(value);\n }}\n renderOption={({ label, value }) => {\n return renderOption({ label, value });\n }}\n />\n );\n}\n\nexport { IconInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { ObjectOptions, StringDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.icon\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of icons to show in the icon picker.\n * @example\n * ```ts\n * iconList: [\n * { label: \"X\", value: \"x\" },\n * { label: \"Check\", value: \"check\" },\n * ]\n * ```\n */\n iconList: ListItems;\n /**\n * A function to render the selected icon value.\n * @example\n * ```ts\n * renderSelected: (value) => <svg><use href={`#icon-${value}`} /></svg>\n * ```\n */\n renderSelected?: (value: string) => React.JSX.Element;\n /** A function to render each icon option in the dropdown.\n * @example\n * ```ts\n * renderOption: (item) => <div>{item.label}</div>\n * ```\n */\n renderOption?: (item: { label?: string; value: string }) => React.JSX.Element;\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whitelist icons by their values.\n */\n whitelist?: string[];\n /**\n * Blacklist icons by their values.\n */\n blacklist?: string[];\n};\n\n// Add the custom field definition to Sanity's intrinsic definitions\n// so that type checking works correctly when using this field type.\ndeclare module \"sanity\" {\n export interface IntrinsicDefinitions {\n [typeName]: Omit<StringDefinition, \"type\" | \"fields\" | \"options\" | \"components\"> & {\n type: typeof typeName;\n options?: FieldOptions;\n };\n }\n}\n","import { definePlugin, defineType } from \"sanity\";\nimport { IconInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityIconFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-icon-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Icon\",\n description: \"Select an icon.\",\n icon: () => <>🧿</>,\n components: {\n input: (props) => <IconInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityIconFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["defaultRenderSelected","value","defaultRenderOption","label","IconInput","t0","$","_c","pluginConfig","props","options","schemaType","iconList","renderOption","renderSelected","whitelist","blacklist","t1","value_0","next","set","unset","onChange","t2","value_1","t3","t4","value_2","_temp","opt","typeName","wildSanityIconFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","components","input"],"mappings":";;;;;AAKA,SAASA,sBAAsBC,OAAe;AAC5C,SAAO,oBAAC,MAAA,EAAK,MAAM,GAAIA,UAAAA,OAAM;AAC/B;AAEA,SAASC,oBAAoB;AAAA,EAAEC;AAAAA,EAAOF;AAAyC,GAAG;AAChF,SACE,oBAAC,QAAK,IAAG,UACP,+BAAC,MAAA,EAAK,OAAM,UAAS,SAAS,GAC5B,UAAA;AAAA,IAAA,oBAAC,UAAK,UAAA,YAAA,CAAE;AAAA,IACR,oBAAC,KAAA,EAAI,MAAM,GAAG,SAAS,GACrB,UAAA,oBAAC,MAAA,EAAK,MAAM,GAAIE,UAAAA,SAASF,MAAAA,CAAM,EAAA,CACjC;AAAA,EAAA,EAAA,CACF,EAAA,CACF;AAEJ;AAEA,SAAAG,UAAAC,IAAA;AAAA,QAAAC,IAAAC,EAAA,EAAA;AAAA,MAAAC,cAAAC;AAAAH,WAAAD,MAAmB;AAAA,IAAAG;AAAAA,IAAA,GAAAC;AAAAA,EAAAA,IAAAJ,IAKlBC,OAAAD,IAAAC,OAAAE,cAAAF,OAAAG,UAAAD,eAAAF,EAAA,CAAA,GAAAG,QAAAH,EAAA,CAAA;AACC,QAAAI,UAAgBD,MAAKE,WAAWD,SAChCE,WAAiBJ,aAAYI,UAC7BC,eAAqBL,aAAYK,gBAAZX,qBACrBY,iBAAuBN,aAAYM,kBAAZd,uBAEvBe,YAAkBL,SAAOK,WACzBC,YAAkBN,SAAOM;AAAY,MAAAC;AAAAX,WAAAG,SAWvBQ,KAAAC,CAAAA,YAAA;AACR,UAAAC,OAAalB,UAAQmB,IAAInB,OAAe,IAANoB,MAAAA;AAAQ,WACnCZ,MAAKa,SAAUH,IAAI;AAAA,EAAC,GA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,MACTH,MAAMJ;AAAAA,MACNQ,MAAM;AAAA,MACNC,OAAO;AAAA,MACPC,aAAa;AAAA,MACbC,MAAMA,MAAM,oBAAA,UAAA,EAAE,UAAA,YAAA,CAAE;AAAA,MAChBC,YAAY;AAAA,QACVC,OAAQlC,CAAAA,UAAU,oBAAC,aAAU,cAAcwB,QAAQ,GAAIxB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAC/D,CACD,CAAC;AAAA,EAAA;AAGR,EACD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madebywild/sanity-icon-field",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"access": "restricted"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@madebywild/sanity-utils": "0.3.
|
|
24
|
+
"@madebywild/sanity-utils": "0.3.14"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@sanity/ui": "^3.1",
|
package/src/types.tsx
CHANGED
|
@@ -50,7 +50,7 @@ export type FieldOptions = ObjectOptions & {
|
|
|
50
50
|
// so that type checking works correctly when using this field type.
|
|
51
51
|
declare module "sanity" {
|
|
52
52
|
export interface IntrinsicDefinitions {
|
|
53
|
-
[typeName]: Omit<StringDefinition, "type" | "fields" | "options"> & {
|
|
53
|
+
[typeName]: Omit<StringDefinition, "type" | "fields" | "options" | "components"> & {
|
|
54
54
|
type: typeof typeName;
|
|
55
55
|
options?: FieldOptions;
|
|
56
56
|
};
|