@madebywild/sanity-color-field 2.0.0 → 3.0.1
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/README.md +6 -4
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/input.tsx +3 -3
- package/src/types.tsx +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
Sanity field type for curated color selection with optional filtering.
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
## Install
|
|
10
9
|
|
|
11
10
|
```bash
|
|
@@ -15,6 +14,7 @@ pnpm add @madebywild/sanity-color-field
|
|
|
15
14
|
## Configure Plugin
|
|
16
15
|
|
|
17
16
|
```ts
|
|
17
|
+
import { defineConfig } from "sanity";
|
|
18
18
|
import { wildSanityColorFieldPlugin } from "@madebywild/sanity-color-field";
|
|
19
19
|
|
|
20
20
|
export default defineConfig({
|
|
@@ -23,9 +23,9 @@ export default defineConfig({
|
|
|
23
23
|
colorList: [
|
|
24
24
|
{ label: "Brand Red", value: "#d92d20" },
|
|
25
25
|
{ label: "Brand Blue", value: "#175cd3" },
|
|
26
|
+
{ label: "Neutral", value: "#667085" },
|
|
26
27
|
],
|
|
27
|
-
|
|
28
|
-
renderValuePreview: (value) => <span style={{ backgroundColor: value }} />,
|
|
28
|
+
renderValue: (value) => <span style={{ backgroundColor: value, width: 16, height: 16, borderRadius: 999 }} />,
|
|
29
29
|
}),
|
|
30
30
|
],
|
|
31
31
|
});
|
|
@@ -34,12 +34,14 @@ export default defineConfig({
|
|
|
34
34
|
## Use in Schema
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
+
import { defineField } from "sanity";
|
|
38
|
+
|
|
37
39
|
defineField({
|
|
38
40
|
name: "themeColor",
|
|
39
41
|
type: "wild.color",
|
|
40
42
|
options: {
|
|
41
|
-
// Per-field subset of the plugin's global `colorList`.
|
|
42
43
|
whitelist: ["#d92d20", "#175cd3"],
|
|
44
|
+
blacklist: ["#667085"],
|
|
43
45
|
},
|
|
44
46
|
});
|
|
45
47
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -23,24 +23,24 @@ function ColorInput(t0) {
|
|
|
23
23
|
pluginConfig,
|
|
24
24
|
...props
|
|
25
25
|
} = t0, $[0] = t0, $[1] = pluginConfig, $[2] = props) : (pluginConfig = $[1], props = $[2]);
|
|
26
|
-
const options = props.schemaType.options, colorList = pluginConfig.colorList,
|
|
26
|
+
const options = props.schemaType.options, colorList = pluginConfig.colorList, renderValue = pluginConfig.renderValue ?? defaultRenderValuePreview, whitelist = options?.whitelist, blacklist = options?.blacklist;
|
|
27
27
|
let t1;
|
|
28
28
|
$[3] !== props ? (t1 = (value_0) => {
|
|
29
29
|
const next = value_0 ? sanity.set(value_0) : sanity.unset();
|
|
30
30
|
return props.onChange(next);
|
|
31
31
|
}, $[3] = props, $[4] = t1) : t1 = $[4];
|
|
32
32
|
let t2, t3;
|
|
33
|
-
$[5] !==
|
|
33
|
+
$[5] !== renderValue ? (t2 = (value_1) => renderValue(value_1), t3 = (t42) => {
|
|
34
34
|
const {
|
|
35
35
|
label,
|
|
36
36
|
value: value_2
|
|
37
|
-
} = t42, preview =
|
|
37
|
+
} = t42, preview = renderValue(value_2);
|
|
38
38
|
return defaultRenderOption({
|
|
39
39
|
label,
|
|
40
40
|
value: value_2,
|
|
41
41
|
preview
|
|
42
42
|
});
|
|
43
|
-
}, $[5] =
|
|
43
|
+
}, $[5] = renderValue, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]);
|
|
44
44
|
let t4;
|
|
45
45
|
return $[8] !== blacklist || $[9] !== colorList || $[10] !== props.value || $[11] !== t1 || $[12] !== t2 || $[13] !== t3 || $[14] !== whitelist ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(asyncAutocomplete.AsyncAutocomplete, { placeholder: "Select color", noOptionsPlaceholder: "No colors found", listItems: colorList, whitelist, blacklist, value: props.value, renderValue: _temp, onChange: t1, renderSelected: t2, renderOption: t3 }), $[8] = blacklist, $[9] = colorList, $[10] = props.value, $[11] = t1, $[12] = t2, $[13] = t3, $[14] = whitelist, $[15] = t4) : t4 = $[15], t4;
|
|
46
46
|
}
|
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 { Avatar, Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\n/** @public */\nfunction defaultRenderValuePreview(value: string) {\n return <Avatar style={{ backgroundColor: value }} />;\n}\n\n/** @public */\nfunction defaultRenderOption({ label, value, preview }: { label?: React.ReactNode; value: string; preview: React.ReactNode }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n {preview}\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction ColorInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const colorList = pluginConfig.colorList;\n const
|
|
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 { Avatar, Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\n/** @public */\nfunction defaultRenderValuePreview(value: string) {\n return <Avatar style={{ backgroundColor: value }} />;\n}\n\n/** @public */\nfunction defaultRenderOption({ label, value, preview }: { label?: React.ReactNode; value: string; preview: React.ReactNode }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n {preview}\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction ColorInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const colorList = pluginConfig.colorList;\n const renderValue = pluginConfig.renderValue ?? defaultRenderValuePreview;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select color\"\n noOptionsPlaceholder=\"No colors found\"\n listItems={colorList}\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 renderValue(value);\n }}\n renderOption={({ label, value }) => {\n const preview = renderValue(value);\n return defaultRenderOption({ label, value, preview });\n }}\n />\n );\n}\n\nexport { ColorInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { ObjectOptions, StringDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.color\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of colors to show in the color picker.\n * In addition to the value, the field will also calculate\n * and store the color's luminance in a separate field.\n * @example\n * ```ts\n * colorList: [\n * { label: \"Red\", value: \"#ff0000\" },\n * { label: \"Green\", value: \"#00ff00\" },\n * { label: \"Blue\", value: \"#0000ff\" },\n * ]\n * ```\n */\n colorList: ListItems;\n /**\n * A function to render the selected color value.\n * @example\n * ```ts\n * renderValue: (value) => <div style={{ backgroundColor: value, width: 20, height: 20 }} />\n * ```\n */\n renderValue?: (value: string) => React.ReactNode;\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whitelist colors by their values.\n */\n whitelist?: string[];\n /**\n * Blacklist colors 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 { ColorInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityColorFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-color-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Color\",\n description: \"Select a color.\",\n icon: () => <>🎨</>,\n components: {\n input: (props) => <ColorInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityColorFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["defaultRenderValuePreview","value","jsx","Avatar","backgroundColor","defaultRenderOption","label","preview","Card","Flex","Box","Text","ColorInput","t0","$","_c","pluginConfig","props","options","schemaType","colorList","renderValue","whitelist","blacklist","t1","value_0","next","set","unset","onChange","t2","t3","value_1","t4","value_2","AsyncAutocomplete","_temp","opt","typeName","wildSanityColorFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","Fragment","components","input"],"mappings":";;;AAMA,SAASA,0BAA0BC,OAAe;AAChD,SAAOC,2BAAAA,IAACC,aAAO,OAAO;AAAA,IAAEC,iBAAiBH;AAAAA,EAAAA,GAAQ;AACnD;AAGA,SAASI,oBAAoB;AAAA,EAAEC;AAAAA,EAAOL;AAAAA,EAAOM;AAA8E,GAAG;AAC5H,SACEL,2BAAAA,IAACM,GAAAA,QAAK,IAAG,UACP,0CAACC,GAAAA,MAAA,EAAK,OAAM,UAAS,SAAS,GAC3BF,UAAAA;AAAAA,IAAAA;AAAAA,IACDL,2BAAA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.
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
33
|
-
*
|
|
33
|
+
* renderValue: (value) => <div style={{ backgroundColor: value, width: 20, height: 20 }} />
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
renderValue?: (value: string) => React.ReactNode;
|
|
37
37
|
};
|
|
38
38
|
/** @public */
|
|
39
39
|
type FieldOptions = ObjectOptions & {
|
package/dist/index.d.ts
CHANGED
|
@@ -30,10 +30,10 @@ type PluginConfig = {
|
|
|
30
30
|
* A function to render the selected color value.
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
33
|
-
*
|
|
33
|
+
* renderValue: (value) => <div style={{ backgroundColor: value, width: 20, height: 20 }} />
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
renderValue?: (value: string) => React.ReactNode;
|
|
37
37
|
};
|
|
38
38
|
/** @public */
|
|
39
39
|
type FieldOptions = ObjectOptions & {
|
package/dist/index.js
CHANGED
|
@@ -25,24 +25,24 @@ function ColorInput(t0) {
|
|
|
25
25
|
pluginConfig,
|
|
26
26
|
...props
|
|
27
27
|
} = t0, $[0] = t0, $[1] = pluginConfig, $[2] = props) : (pluginConfig = $[1], props = $[2]);
|
|
28
|
-
const options = props.schemaType.options, colorList = pluginConfig.colorList,
|
|
28
|
+
const options = props.schemaType.options, colorList = pluginConfig.colorList, renderValue = pluginConfig.renderValue ?? defaultRenderValuePreview, whitelist = options?.whitelist, blacklist = options?.blacklist;
|
|
29
29
|
let t1;
|
|
30
30
|
$[3] !== props ? (t1 = (value_0) => {
|
|
31
31
|
const next = value_0 ? set(value_0) : unset();
|
|
32
32
|
return props.onChange(next);
|
|
33
33
|
}, $[3] = props, $[4] = t1) : t1 = $[4];
|
|
34
34
|
let t2, t3;
|
|
35
|
-
$[5] !==
|
|
35
|
+
$[5] !== renderValue ? (t2 = (value_1) => renderValue(value_1), t3 = (t42) => {
|
|
36
36
|
const {
|
|
37
37
|
label,
|
|
38
38
|
value: value_2
|
|
39
|
-
} = t42, preview =
|
|
39
|
+
} = t42, preview = renderValue(value_2);
|
|
40
40
|
return defaultRenderOption({
|
|
41
41
|
label,
|
|
42
42
|
value: value_2,
|
|
43
43
|
preview
|
|
44
44
|
});
|
|
45
|
-
}, $[5] =
|
|
45
|
+
}, $[5] = renderValue, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]);
|
|
46
46
|
let t4;
|
|
47
47
|
return $[8] !== blacklist || $[9] !== colorList || $[10] !== props.value || $[11] !== t1 || $[12] !== t2 || $[13] !== t3 || $[14] !== whitelist ? (t4 = /* @__PURE__ */ jsx(AsyncAutocomplete, { placeholder: "Select color", noOptionsPlaceholder: "No colors found", listItems: colorList, whitelist, blacklist, value: props.value, renderValue: _temp, onChange: t1, renderSelected: t2, renderOption: t3 }), $[8] = blacklist, $[9] = colorList, $[10] = props.value, $[11] = t1, $[12] = t2, $[13] = t3, $[14] = whitelist, $[15] = t4) : t4 = $[15], t4;
|
|
48
48
|
}
|
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 { Avatar, Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\n/** @public */\nfunction defaultRenderValuePreview(value: string) {\n return <Avatar style={{ backgroundColor: value }} />;\n}\n\n/** @public */\nfunction defaultRenderOption({ label, value, preview }: { label?: React.ReactNode; value: string; preview: React.ReactNode }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n {preview}\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction ColorInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const colorList = pluginConfig.colorList;\n const
|
|
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 { Avatar, Box, Card, Flex, Text } from \"@sanity/ui\";\nimport { type StringInputProps, set, unset } from \"sanity\";\nimport type { FieldOptions, PluginConfig } from \"./types\";\n\n/** @public */\nfunction defaultRenderValuePreview(value: string) {\n return <Avatar style={{ backgroundColor: value }} />;\n}\n\n/** @public */\nfunction defaultRenderOption({ label, value, preview }: { label?: React.ReactNode; value: string; preview: React.ReactNode }) {\n return (\n <Card as=\"button\">\n <Flex align=\"center\" padding={2}>\n {preview}\n <Box flex={1} padding={2}>\n <Text size={2}>{label ?? value}</Text>\n </Box>\n </Flex>\n </Card>\n );\n}\n\nfunction ColorInput({\n pluginConfig,\n ...props\n}: StringInputProps & {\n pluginConfig: PluginConfig;\n}) {\n const options = props.schemaType.options as FieldOptions | undefined;\n const colorList = pluginConfig.colorList;\n const renderValue = pluginConfig.renderValue ?? defaultRenderValuePreview;\n\n const whitelist = options?.whitelist;\n const blacklist = options?.blacklist;\n\n return (\n <AsyncAutocomplete\n placeholder=\"Select color\"\n noOptionsPlaceholder=\"No colors found\"\n listItems={colorList}\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 renderValue(value);\n }}\n renderOption={({ label, value }) => {\n const preview = renderValue(value);\n return defaultRenderOption({ label, value, preview });\n }}\n />\n );\n}\n\nexport { ColorInput };\n","import type { ListItems } from \"@madebywild/sanity-utils/async-autocomplete\";\nimport type { ObjectOptions, StringDefinition } from \"sanity\";\n\n/** @public */\nexport const typeName = \"wild.color\" as const;\n\n/** @public */\nexport type PluginConfig = {\n /**\n * A list of colors to show in the color picker.\n * In addition to the value, the field will also calculate\n * and store the color's luminance in a separate field.\n * @example\n * ```ts\n * colorList: [\n * { label: \"Red\", value: \"#ff0000\" },\n * { label: \"Green\", value: \"#00ff00\" },\n * { label: \"Blue\", value: \"#0000ff\" },\n * ]\n * ```\n */\n colorList: ListItems;\n /**\n * A function to render the selected color value.\n * @example\n * ```ts\n * renderValue: (value) => <div style={{ backgroundColor: value, width: 20, height: 20 }} />\n * ```\n */\n renderValue?: (value: string) => React.ReactNode;\n};\n\n/** @public */\nexport type FieldOptions = ObjectOptions & {\n /**\n * Whitelist colors by their values.\n */\n whitelist?: string[];\n /**\n * Blacklist colors 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 { ColorInput } from \"./input\";\nimport { type FieldOptions, type PluginConfig, typeName } from \"./types\";\n\n/** @public */\nconst wildSanityColorFieldPlugin = definePlugin<PluginConfig>((config) => {\n return {\n name: \"@madebywild/sanity-color-field\",\n schema: {\n types: [\n defineType({\n name: typeName,\n type: \"string\",\n title: \"Color\",\n description: \"Select a color.\",\n icon: () => <>🎨</>,\n components: {\n input: (props) => <ColorInput pluginConfig={config} {...props} />,\n },\n }),\n ],\n },\n };\n});\n\nexport { wildSanityColorFieldPlugin, typeName, type PluginConfig, type FieldOptions };\n"],"names":["defaultRenderValuePreview","value","backgroundColor","defaultRenderOption","label","preview","ColorInput","t0","$","_c","pluginConfig","props","options","schemaType","colorList","renderValue","whitelist","blacklist","t1","value_0","next","set","unset","onChange","t2","t3","value_1","t4","value_2","_temp","opt","typeName","wildSanityColorFieldPlugin","definePlugin","config","name","schema","types","defineType","type","title","description","icon","components","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U,oBAAC,cAAW,cAAcuB,QAAQ,GAAIvB,MAAAA,CAAM;AAAA,MAAA;AAAA,IAChE,CACD,CAAC;AAAA,EAAA;AAGR,EACD;"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madebywild/sanity-color-field",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "MIT",
|
|
7
7
|
"browserslist": "extends @sanity/browserslist-config",
|
|
8
8
|
"exports": {
|
|
9
9
|
"./package.json": "./package.json",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@madebywild/sanity-utils": "1.0.
|
|
24
|
+
"@madebywild/sanity-utils": "1.0.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@sanity/ui": "^3.1",
|
package/src/input.tsx
CHANGED
|
@@ -30,7 +30,7 @@ function ColorInput({
|
|
|
30
30
|
}) {
|
|
31
31
|
const options = props.schemaType.options as FieldOptions | undefined;
|
|
32
32
|
const colorList = pluginConfig.colorList;
|
|
33
|
-
const
|
|
33
|
+
const renderValue = pluginConfig.renderValue ?? defaultRenderValuePreview;
|
|
34
34
|
|
|
35
35
|
const whitelist = options?.whitelist;
|
|
36
36
|
const blacklist = options?.blacklist;
|
|
@@ -49,10 +49,10 @@ function ColorInput({
|
|
|
49
49
|
return props.onChange(next);
|
|
50
50
|
}}
|
|
51
51
|
renderSelected={(value) => {
|
|
52
|
-
return
|
|
52
|
+
return renderValue(value);
|
|
53
53
|
}}
|
|
54
54
|
renderOption={({ label, value }) => {
|
|
55
|
-
const preview =
|
|
55
|
+
const preview = renderValue(value);
|
|
56
56
|
return defaultRenderOption({ label, value, preview });
|
|
57
57
|
}}
|
|
58
58
|
/>
|
package/src/types.tsx
CHANGED
|
@@ -24,10 +24,10 @@ export type PluginConfig = {
|
|
|
24
24
|
* A function to render the selected color value.
|
|
25
25
|
* @example
|
|
26
26
|
* ```ts
|
|
27
|
-
*
|
|
27
|
+
* renderValue: (value) => <div style={{ backgroundColor: value, width: 20, height: 20 }} />
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
renderValue?: (value: string) => React.ReactNode;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/** @public */
|