@madebywild/sanity-icon-field 0.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 +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +23 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +1 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @madebywild/sanity-icon-field
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { definePlugin, defineType } from "sanity";
|
|
3
|
+
import { IconInput } from "./input";
|
|
4
|
+
import { typeName } from "./types";
|
|
5
|
+
const wildSanityIconFieldPlugin = definePlugin((config) => {
|
|
6
|
+
return {
|
|
7
|
+
name: "@madebywild/sanity-icon-field",
|
|
8
|
+
schema: {
|
|
9
|
+
types: [
|
|
10
|
+
defineType({
|
|
11
|
+
name: typeName,
|
|
12
|
+
type: "string",
|
|
13
|
+
title: "Icon",
|
|
14
|
+
description: "Select an icon.",
|
|
15
|
+
icon: () => _jsx(_Fragment, { children: "\uD83E\uDDFF" }),
|
|
16
|
+
components: {
|
|
17
|
+
input: (props) => _jsx(IconInput, { config: config, ...props }),
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
export { wildSanityIconFieldPlugin, typeName };
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type StringInputProps } from "sanity";
|
|
2
|
+
import type { PluginConfig } from "./types";
|
|
3
|
+
declare function IconInput({ config, schemaType, onChange, value, }: StringInputProps & {
|
|
4
|
+
config: PluginConfig;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export { IconInput };
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AsyncAutocomplete } from "@madebywild/sanity-utils";
|
|
3
|
+
import { Box, Card, Flex, Text } from "@sanity/ui";
|
|
4
|
+
import { set, unset } from "sanity";
|
|
5
|
+
function IconInput({ config, schemaType, onChange, value, }) {
|
|
6
|
+
const options = schemaType.options;
|
|
7
|
+
const iconList = options?.iconList ?? config.iconList;
|
|
8
|
+
const renderOption = options?.renderOption ?? config.renderOption;
|
|
9
|
+
const renderSelected = options?.renderSelected ?? config.renderSelected;
|
|
10
|
+
return (_jsx(AsyncAutocomplete, { defaultValue: value, placeholder: "Select icon", listItems: iconList, renderValue: (value, opt) => opt?.label ?? value, onChange: (value) => {
|
|
11
|
+
const next = value ? set(value) : unset();
|
|
12
|
+
return onChange(next);
|
|
13
|
+
}, renderSelected: (value) => {
|
|
14
|
+
if (renderSelected)
|
|
15
|
+
return renderSelected(value);
|
|
16
|
+
return _jsx(Text, { size: 2, children: value });
|
|
17
|
+
}, renderOption: ({ label, value }) => {
|
|
18
|
+
if (renderOption)
|
|
19
|
+
return renderOption({ label, value });
|
|
20
|
+
return (_jsx(Card, { as: "button", children: _jsxs(Flex, { align: "center", padding: 2, children: [_jsx("span", { children: "\uD83E\uDDFF" }), _jsx(Box, { flex: 1, padding: 2, children: _jsx(Text, { size: 2, children: label }) })] }) }));
|
|
21
|
+
} }));
|
|
22
|
+
}
|
|
23
|
+
export { IconInput };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ListItemsGetter } from "@madebywild/sanity-utils";
|
|
2
|
+
import type { StringDefinition, StringOptions } from "sanity";
|
|
3
|
+
export type PluginConfig = {
|
|
4
|
+
iconList: ListItemsGetter;
|
|
5
|
+
renderSelected?: (value: string) => React.JSX.Element;
|
|
6
|
+
renderOption?: (item: {
|
|
7
|
+
label?: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}) => React.JSX.Element;
|
|
10
|
+
};
|
|
11
|
+
export type FieldOptions = StringOptions & {
|
|
12
|
+
iconList?: ListItemsGetter;
|
|
13
|
+
renderSelected?: (value: string) => React.JSX.Element;
|
|
14
|
+
renderOption?: (item: {
|
|
15
|
+
label?: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}) => React.JSX.Element;
|
|
18
|
+
};
|
|
19
|
+
export declare const typeName: "wild.icon";
|
|
20
|
+
declare module "sanity" {
|
|
21
|
+
interface IntrinsicDefinitions {
|
|
22
|
+
[typeName]: Omit<StringDefinition, "type" | "fields"> & {
|
|
23
|
+
type: typeof typeName;
|
|
24
|
+
options?: FieldOptions;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const typeName = "wild.icon";
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@madebywild/sanity-icon-field",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"clear": "rm -rf dist",
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@madebywild/sanity-utils": "*"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"sanity": "^4.17",
|
|
23
|
+
"react": "^19",
|
|
24
|
+
"react-dom": "^19"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"sanity": "^4.17",
|
|
28
|
+
"react": "^19",
|
|
29
|
+
"react-dom": "^19",
|
|
30
|
+
"typescript": "^5.9",
|
|
31
|
+
"@types/react": "^19",
|
|
32
|
+
"@types/react-dom": "^19"
|
|
33
|
+
}
|
|
34
|
+
}
|