@sanity/color-input 3.0.2 → 3.1.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 CHANGED
@@ -10,11 +10,12 @@ Color input plugin for [Sanity](https://sanity.io/) that stores selected colors
10
10
  ![Color input in the Studio](assets/color-input.png)
11
11
 
12
12
  ## Installation
13
+
13
14
  ```
14
15
  npm install --save @sanity/color-input
15
16
  ```
16
17
 
17
- or
18
+ or
18
19
 
19
20
  ```
20
21
  yarn add @sanity/color-input
@@ -25,18 +26,14 @@ yarn add @sanity/color-input
25
26
  Add it as a plugin in sanity.config.ts (or .js):
26
27
 
27
28
  ```js
28
- import { colorInput } from "@sanity/color-input";
29
+ import {colorInput} from '@sanity/color-input'
29
30
 
30
31
  export default defineConfig({
31
32
  // ...
32
- plugins: [
33
- colorInput(),
34
- ]
33
+ plugins: [colorInput()],
35
34
  })
36
35
  ```
37
36
 
38
-
39
-
40
37
  Now you can use the `color` type in your schema types:
41
38
 
42
39
  ```js
@@ -47,14 +44,16 @@ Now you can use the `color` type in your schema types:
47
44
  {
48
45
  name: 'favoriteColor',
49
46
  title: 'Favorite color',
50
- type: 'color'
51
- }
47
+ type: 'color',
48
+ },
52
49
  ]
53
50
  }
54
51
  ```
55
52
 
56
53
  ## Options
57
54
 
55
+ ### Disable alpha
56
+
58
57
  To disable the alpha option, set `disableAlpha` to `true`:
59
58
 
60
59
  ```js
@@ -73,6 +72,36 @@ Which will render accordingly:
73
72
 
74
73
  ![This is an image](assets/no-alpha.png)
75
74
 
75
+ ### Color list
76
+
77
+ To add list of predefined selectable color swatches for the user to choose from use `colorList`.
78
+ This uses the `react-color` under the hood https://casesandberg.github.io/react-color/#api-color
79
+
80
+ ```js
81
+ // ...fields...
82
+ {
83
+ name: 'favoriteColor',
84
+ title: 'Color with list',
85
+ type: 'color',
86
+ options: {
87
+ colorList: [
88
+ '#FF6900',
89
+ { hex: '#FCB900' },
90
+ { r: 123, g: 220, b: 181 },
91
+ { r: 0, g: 208, b: 132, a: 0.5 },
92
+ { h: 203, s: 95, l: 77, a: 1 },
93
+ { h: 202, s: 95, l: 46, a: 0.5 },
94
+ { h: 345, s: 43, v: 97 },
95
+ { h: 344, s: 91, v: 92, a: 0.5 },
96
+ ]
97
+ }
98
+ }
99
+ ```
100
+
101
+ Which will render accordingly:
102
+
103
+ ![This is an image](assets/color-list.png)
104
+
76
105
  ## Data model
77
106
 
78
107
  ```js
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
 
3
+ import {Color} from 'react-color'
3
4
  import {HSLColor} from 'react-color'
4
5
  import {HSVColor} from 'react-color'
5
6
  import {ObjectDefinition} from 'sanity'
@@ -44,6 +45,7 @@ export declare type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaTy
44
45
 
45
46
  export declare interface ColorOptions extends Omit<ObjectOptions, 'columns'> {
46
47
  disableAlpha?: boolean
48
+ colorList?: Array<Color>
47
49
  }
48
50
 
49
51
  export declare type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {