@sanity/color-input 2.30.1 → 3.0.0-studio-v3.0
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 +61 -6
- package/lib/index.d.ts +85 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +606 -0
- package/lib/index.js.map +1 -0
- package/lib/index.modern.js +594 -0
- package/lib/index.modern.js.map +1 -0
- package/package.json +57 -17
- package/src/ColorInput.tsx +110 -0
- package/src/ColorPicker.tsx +139 -0
- package/src/ColorPickerFields.tsx +144 -0
- package/src/index.ts +16 -0
- package/src/schemas/color.tsx +79 -0
- package/src/schemas/hslaColor.ts +11 -0
- package/src/schemas/hsvaColor.ts +11 -0
- package/src/schemas/rgbaColor.ts +11 -0
- package/lib/ColorInput.js +0 -144
- package/lib/ColorPicker.js +0 -159
- package/lib/ColorPickerFields.js +0 -138
- package/lib/schemas/color.js +0 -81
- package/lib/schemas/hslaColor.js +0 -29
- package/lib/schemas/hsvaColor.js +0 -29
- package/lib/schemas/rgbaColor.js +0 -29
- package/sanity.json +0 -32
package/README.md
CHANGED
|
@@ -1,16 +1,46 @@
|
|
|
1
1
|
# @sanity/color-input
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **NOTE**
|
|
4
|
+
>
|
|
5
|
+
> This is the **Sanity Studio v3 version** of @sanity/color-input.
|
|
6
|
+
>
|
|
7
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/color-input).
|
|
8
|
+
|
|
9
|
+
## What is it?
|
|
10
|
+
|
|
11
|
+
Color input plugin for [Sanity](https://sanity.io/) that stores selected colors in hex, hsl, hsv and rgb format.
|
|
12
|
+
|
|
13
|
+

|
|
4
14
|
|
|
5
15
|
## Installation
|
|
16
|
+
```
|
|
17
|
+
npm install --save @sanity/color-input@studio-v3
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
or
|
|
6
21
|
|
|
7
22
|
```
|
|
8
|
-
|
|
23
|
+
yarn add @sanity/color-input@studio-v3
|
|
9
24
|
```
|
|
10
25
|
|
|
11
26
|
## Usage
|
|
12
27
|
|
|
13
|
-
|
|
28
|
+
Add it as a plugin in sanity.config.ts (or .js):
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { colorSchema } from "@sanity/color-input";
|
|
32
|
+
|
|
33
|
+
export default createConfig({
|
|
34
|
+
// ...
|
|
35
|
+
plugins: [
|
|
36
|
+
colorSchema(),
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Now you can use the `color` type in your schema types:
|
|
14
44
|
|
|
15
45
|
```js
|
|
16
46
|
// [...]
|
|
@@ -26,8 +56,6 @@ Use it in your schema types:
|
|
|
26
56
|
}
|
|
27
57
|
```
|
|
28
58
|
|
|
29
|
-
Note that the above only works if you import and use the `all:part:@sanity/base/schema-type` part in your schema.
|
|
30
|
-
|
|
31
59
|
## Options
|
|
32
60
|
|
|
33
61
|
To disable the alpha option, set `disableAlpha` to `true`:
|
|
@@ -36,7 +64,7 @@ To disable the alpha option, set `disableAlpha` to `true`:
|
|
|
36
64
|
// ...fields...
|
|
37
65
|
{
|
|
38
66
|
name: 'favoriteColor',
|
|
39
|
-
title: '
|
|
67
|
+
title: 'Color no-alpha',
|
|
40
68
|
type: 'color',
|
|
41
69
|
options: {
|
|
42
70
|
disableAlpha: true
|
|
@@ -44,6 +72,10 @@ To disable the alpha option, set `disableAlpha` to `true`:
|
|
|
44
72
|
}
|
|
45
73
|
```
|
|
46
74
|
|
|
75
|
+
Which will render accordingly:
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
47
79
|
## Data model
|
|
48
80
|
|
|
49
81
|
```js
|
|
@@ -78,3 +110,26 @@ To disable the alpha option, set `disableAlpha` to `true`:
|
|
|
78
110
|
## License
|
|
79
111
|
|
|
80
112
|
MIT-licensed. See LICENSE.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
## Develop & test
|
|
116
|
+
|
|
117
|
+
Make sure to run `npm run build` once, then run
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm run link-watch
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
In another shell, `cd` to your test studio and run:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npx yalc add @sanity/color-input --link && yarn install
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Now, changes in this repo will be automatically built and pushed to the studio,
|
|
130
|
+
triggering hotreload. Yalc avoids issues with react-hooks that are typical when using yarn/npm link.
|
|
131
|
+
|
|
132
|
+
### About build & watch
|
|
133
|
+
|
|
134
|
+
This plugin uses [@sanity/plugin-sdk](https://github.com/sanity-io/plugin-sdk)
|
|
135
|
+
with default configuration for build & watch scripts.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ObjectInputProps } from "sanity";
|
|
2
|
+
import { HSLColor, HSVColor, RGBColor } from "react-color";
|
|
3
|
+
import { ObjectSchemaType } from "@sanity/types";
|
|
4
|
+
export const hslaColor: {
|
|
5
|
+
title: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
fields: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
title: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export const rgbaColor: {
|
|
15
|
+
title: string;
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
fields: {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
title: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
export interface ColorValue {
|
|
25
|
+
hex: string;
|
|
26
|
+
hsl: HSLColor;
|
|
27
|
+
hsv: HSVColor;
|
|
28
|
+
rgb: RGBColor;
|
|
29
|
+
}
|
|
30
|
+
export interface ColorOptions {
|
|
31
|
+
disableAlpha?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export type ColorSchemaType = ObjectSchemaType & {
|
|
34
|
+
options?: ColorOptions;
|
|
35
|
+
};
|
|
36
|
+
export type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>;
|
|
37
|
+
export function ColorInput(props: ColorInputProps): JSX.Element;
|
|
38
|
+
export const color: {
|
|
39
|
+
name: string;
|
|
40
|
+
type: string;
|
|
41
|
+
title: string;
|
|
42
|
+
components: {
|
|
43
|
+
input: typeof ColorInput;
|
|
44
|
+
};
|
|
45
|
+
fields: {
|
|
46
|
+
title: string;
|
|
47
|
+
name: string;
|
|
48
|
+
type: string;
|
|
49
|
+
}[];
|
|
50
|
+
preview: {
|
|
51
|
+
select: {
|
|
52
|
+
title: string;
|
|
53
|
+
alpha: string;
|
|
54
|
+
hex: string;
|
|
55
|
+
hsl: string;
|
|
56
|
+
};
|
|
57
|
+
prepare({ title, hex, hsl, alpha, }: {
|
|
58
|
+
title?: string | undefined;
|
|
59
|
+
alpha?: number | undefined;
|
|
60
|
+
hex?: string | undefined;
|
|
61
|
+
hsl?: {
|
|
62
|
+
h: number;
|
|
63
|
+
s: number;
|
|
64
|
+
l: number;
|
|
65
|
+
} | undefined;
|
|
66
|
+
}): {
|
|
67
|
+
title: string | undefined;
|
|
68
|
+
subtitle: string;
|
|
69
|
+
media: () => JSX.Element;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export const hsvaColor: {
|
|
74
|
+
title: string;
|
|
75
|
+
name: string;
|
|
76
|
+
type: string;
|
|
77
|
+
fields: {
|
|
78
|
+
name: string;
|
|
79
|
+
type: string;
|
|
80
|
+
title: string;
|
|
81
|
+
}[];
|
|
82
|
+
};
|
|
83
|
+
export const colorInput: import("sanity").Plugin<void>;
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA,OAAO,MAAM;;;;;;;;;CAUZ,CAAA;ACVD,OAAO,MAAM;;;;;;;;;CAUZ,CAAA;AGQD;IACE,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,QAAQ,CAAA;IACb,GAAG,EAAE,QAAQ,CAAA;IACb,GAAG,EAAE,QAAQ,CAAA;CACd;AAED;IACE,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,8BAA8B,gBAAgB,GAAG;IAC/C,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB,CAAA;AACD,8BAA8B,iBAAiB,UAAU,EAAE,eAAe,CAAC,CAAA;AAE3E,2BAA2B,KAAK,EAAE,eAAe,eA2EhD;ACxGD,OAAO,MAAM;;;;;;;;;;;;;;;;;;;;;;;;mBAgDG,MAAM;mBAAK,MAAM;mBAAK,MAAM;;;;;;;;CAyB3C,CAAA;AC9ED,OAAO,MAAM;;;;;;;;;CAUZ,CAAA;ACJD,OAAO,MAAM,yCAKX,CAAA","sources":["src/src/schemas/hslaColor.ts","src/src/schemas/rgbaColor.ts","src/src/ColorPickerFields.tsx","src/src/ColorPicker.tsx","src/src/ColorInput.tsx","src/src/schemas/color.tsx","src/src/schemas/hsvaColor.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"import {createPlugin} from 'sanity'\nimport {hslaColor} from './schemas/hslaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\nimport {color} from './schemas/color'\nimport {hsvaColor} from './schemas/hsvaColor'\n\nexport const colorInput = createPlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {hslaColor, rgbaColor, color, hsvaColor}\nexport {ColorInput} from './ColorInput'\nexport type {ColorValue, ColorInputProps, ColorOptions, ColorSchemaType} from './ColorInput'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../"}
|