@sanity/color-input 2.36.0-v2-studio.1 → 2.36.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 +1 -1
- package/package.json +7 -2
- package/src/ColorInput.js +113 -0
- package/src/ColorPicker.js +144 -0
- package/src/ColorPickerFields.js +128 -0
- package/src/schemas/color.js +70 -0
- package/src/schemas/hslaColor.js +11 -0
- package/src/schemas/hsvaColor.js +11 -0
- package/src/schemas/rgbaColor.js +11 -0
- package/.eslintrc.js +0 -25
- package/.github/workflows/main.yml +0 -133
- package/.husky/commit-msg +0 -4
- package/.husky/pre-commit +0 -4
- package/.prettierrc +0 -8
- package/.releaserc.json +0 -4
- package/.semantic-release/sanity-color-input-2.36.0-v2-studio.1.tgz +0 -0
- package/CHANGELOG.md +0 -12
- package/assets/color-input.png +0 -0
- package/assets/no-alpha.png +0 -0
- package/commitlint.config.js +0 -3
- package/lint-staged.config.js +0 -4
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/color-input",
|
|
3
|
-
"version": "2.36.0
|
|
3
|
+
"version": "2.36.0",
|
|
4
4
|
"description": "Color input for Sanity Studio",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"homepage": "https://www.sanity.io/",
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "
|
|
16
|
+
"url": "https://github.com/sanity-io/color-input/issues"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"author": "Sanity.io <hello@sanity.io>",
|
|
24
24
|
"main": "lib/schemas/color.js",
|
|
25
|
+
"files": [
|
|
26
|
+
"lib",
|
|
27
|
+
"src",
|
|
28
|
+
"sanity.json"
|
|
29
|
+
],
|
|
25
30
|
"scripts": {
|
|
26
31
|
"prebuild": "npm run clean",
|
|
27
32
|
"build": "sanipack build",
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
///<reference types="@sanity/types/parts" />
|
|
2
|
+
|
|
3
|
+
/* eslint-disable id-length */
|
|
4
|
+
import React, {PureComponent} from 'react'
|
|
5
|
+
import PropTypes from 'prop-types'
|
|
6
|
+
import {PatchEvent, patches} from 'part:@sanity/form-builder'
|
|
7
|
+
import {debounce} from 'lodash'
|
|
8
|
+
import {Button} from '@sanity/ui'
|
|
9
|
+
import {AddIcon} from '@sanity/icons'
|
|
10
|
+
import {FormField} from '@sanity/base/components'
|
|
11
|
+
import ColorPicker from './ColorPicker'
|
|
12
|
+
|
|
13
|
+
const {set, unset, setIfMissing} = patches
|
|
14
|
+
|
|
15
|
+
const DEFAULT_COLOR = {
|
|
16
|
+
hex: '#24a3e3',
|
|
17
|
+
hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},
|
|
18
|
+
hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},
|
|
19
|
+
rgb: {r: 46, g: 163, b: 227, a: 1},
|
|
20
|
+
source: 'hex',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default class ColorInput extends PureComponent {
|
|
24
|
+
focusRef = React.createRef()
|
|
25
|
+
static propTypes = {
|
|
26
|
+
type: PropTypes.shape({
|
|
27
|
+
name: PropTypes.string,
|
|
28
|
+
title: PropTypes.string,
|
|
29
|
+
description: PropTypes.string,
|
|
30
|
+
fields: PropTypes.arrayOf(
|
|
31
|
+
PropTypes.shape({
|
|
32
|
+
name: PropTypes.string.isRequired,
|
|
33
|
+
})
|
|
34
|
+
),
|
|
35
|
+
}).isRequired,
|
|
36
|
+
onChange: PropTypes.func.isRequired,
|
|
37
|
+
readOnly: PropTypes.bool,
|
|
38
|
+
value: PropTypes.shape({
|
|
39
|
+
hex: PropTypes.string,
|
|
40
|
+
alpha: PropTypes.number,
|
|
41
|
+
}),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
focus() {
|
|
45
|
+
// todo: make the ColorPicker component support .focus()
|
|
46
|
+
if (this.focusRef.current && this.focusRef.current.focus) {
|
|
47
|
+
this.focusRef.current.focus()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
emitSetColor = (nextColor) => {
|
|
52
|
+
const {onChange, type} = this.props
|
|
53
|
+
|
|
54
|
+
const fieldPatches = type.fields
|
|
55
|
+
.filter((field) => field.name in nextColor)
|
|
56
|
+
.map((field) => {
|
|
57
|
+
const nextFieldValue = nextColor[field.name]
|
|
58
|
+
const isObject = field.type.jsonType === 'object'
|
|
59
|
+
return set(
|
|
60
|
+
isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,
|
|
61
|
+
[field.name]
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
onChange(
|
|
66
|
+
PatchEvent.from([
|
|
67
|
+
setIfMissing({_type: type.name}),
|
|
68
|
+
set(type.name, ['_type']),
|
|
69
|
+
set(nextColor.rgb.a, ['alpha']),
|
|
70
|
+
...fieldPatches,
|
|
71
|
+
])
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The color picker emits onChange events continuously while the user is sliding the
|
|
76
|
+
// hue/saturation/alpha selectors. This debounces the event to avoid excessive patches
|
|
77
|
+
handleColorChange = debounce(this.emitSetColor, 100)
|
|
78
|
+
|
|
79
|
+
handleCreateColor = () => {
|
|
80
|
+
this.emitSetColor(DEFAULT_COLOR)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
handleUnset = () => {
|
|
84
|
+
this.props.onChange(PatchEvent.from(unset()))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
render() {
|
|
88
|
+
const {type, readOnly, value, level} = this.props
|
|
89
|
+
return (
|
|
90
|
+
<FormField title={type.title} description={type.description} level={level}>
|
|
91
|
+
{value ? (
|
|
92
|
+
<ColorPicker
|
|
93
|
+
ref={this.focusRef}
|
|
94
|
+
color={value.hsl || value.hex}
|
|
95
|
+
readOnly={readOnly || type.readOnly}
|
|
96
|
+
onChange={this.handleColorChange}
|
|
97
|
+
disableAlpha={type.options && type.options.disableAlpha}
|
|
98
|
+
onUnset={this.handleUnset}
|
|
99
|
+
/>
|
|
100
|
+
) : (
|
|
101
|
+
<Button
|
|
102
|
+
icon={AddIcon}
|
|
103
|
+
mode="ghost"
|
|
104
|
+
text="Create color"
|
|
105
|
+
ref={this.focusRef}
|
|
106
|
+
disabled={Boolean(readOnly)}
|
|
107
|
+
onClick={this.handleCreateColor}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
</FormField>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import {ColorWrap, Checkboard, Saturation, Hue, Alpha} from 'react-color/lib/components/common'
|
|
4
|
+
import {Box, Card, Flex, Button, Inline, Stack, Text} from '@sanity/ui'
|
|
5
|
+
import {TrashIcon} from '@sanity/icons'
|
|
6
|
+
import styled from 'styled-components'
|
|
7
|
+
import {ColorPickerFields} from './ColorPickerFields'
|
|
8
|
+
|
|
9
|
+
const ColorBox = styled(Box)`
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: 0;
|
|
12
|
+
left: 0;
|
|
13
|
+
width: 100%;
|
|
14
|
+
height: 100%;
|
|
15
|
+
`
|
|
16
|
+
|
|
17
|
+
const ReadOnlyContainer = styled(Flex)`
|
|
18
|
+
margin-top: 6rem;
|
|
19
|
+
background-color: var(--card-bg-color);
|
|
20
|
+
position: relative;
|
|
21
|
+
width: 100%;
|
|
22
|
+
`
|
|
23
|
+
|
|
24
|
+
const ColorPicker = ({
|
|
25
|
+
width,
|
|
26
|
+
rgb,
|
|
27
|
+
hex,
|
|
28
|
+
hsv,
|
|
29
|
+
hsl,
|
|
30
|
+
onChange,
|
|
31
|
+
onUnset,
|
|
32
|
+
disableAlpha,
|
|
33
|
+
renderers,
|
|
34
|
+
readOnly,
|
|
35
|
+
}) => {
|
|
36
|
+
return (
|
|
37
|
+
<div style={{width}}>
|
|
38
|
+
<Card padding={1} border radius={1}>
|
|
39
|
+
<Stack space={2}>
|
|
40
|
+
{!readOnly && (
|
|
41
|
+
<>
|
|
42
|
+
<Card overflow="hidden" style={{position: 'relative', height: '5em'}}>
|
|
43
|
+
<Saturation is="Saturation" onChange={onChange} hsl={hsl} hsv={hsv} />
|
|
44
|
+
</Card>
|
|
45
|
+
|
|
46
|
+
<Card
|
|
47
|
+
shadow={1}
|
|
48
|
+
radius={3}
|
|
49
|
+
overflow="hidden"
|
|
50
|
+
style={{position: 'relative', height: '10px'}}
|
|
51
|
+
>
|
|
52
|
+
<Hue is="Hue" hsl={hsl} onChange={!readOnly && onChange} />
|
|
53
|
+
</Card>
|
|
54
|
+
|
|
55
|
+
{!disableAlpha && (
|
|
56
|
+
<Card
|
|
57
|
+
shadow={1}
|
|
58
|
+
radius={3}
|
|
59
|
+
overflow="hidden"
|
|
60
|
+
style={{position: 'relative', height: '10px'}}
|
|
61
|
+
>
|
|
62
|
+
<Alpha is="Alpha" rgb={rgb} hsl={hsl} renderers={renderers} onChange={onChange} />
|
|
63
|
+
</Card>
|
|
64
|
+
)}
|
|
65
|
+
</>
|
|
66
|
+
)}
|
|
67
|
+
<Flex>
|
|
68
|
+
<Card
|
|
69
|
+
flex={1}
|
|
70
|
+
radius={2}
|
|
71
|
+
overflow="hidden"
|
|
72
|
+
style={{position: 'relative', minWidth: '4em'}}
|
|
73
|
+
>
|
|
74
|
+
<Checkboard />
|
|
75
|
+
<ColorBox style={{backgroundColor: `rgba(${rgb.r},${rgb.g},${rgb.b},${rgb.a})`}} />
|
|
76
|
+
|
|
77
|
+
{readOnly && (
|
|
78
|
+
<ReadOnlyContainer
|
|
79
|
+
padding={2}
|
|
80
|
+
paddingBottom={1}
|
|
81
|
+
sizing="border"
|
|
82
|
+
justify="space-between"
|
|
83
|
+
>
|
|
84
|
+
<Stack space={3} marginTop={1}>
|
|
85
|
+
<Text size={3} weight="bold">
|
|
86
|
+
{hex}
|
|
87
|
+
</Text>
|
|
88
|
+
|
|
89
|
+
<Inline space={3}>
|
|
90
|
+
<Text size={1}>
|
|
91
|
+
<strong>RGB: </strong>
|
|
92
|
+
{rgb.r} {rgb.g} {rgb.b}
|
|
93
|
+
</Text>
|
|
94
|
+
<Text size={1}>
|
|
95
|
+
<strong>HSL: </strong> {Math.round(hsl.h)} {Math.round(hsl.s)}%{' '}
|
|
96
|
+
{Math.round(hsl.l)}
|
|
97
|
+
</Text>
|
|
98
|
+
</Inline>
|
|
99
|
+
</Stack>
|
|
100
|
+
</ReadOnlyContainer>
|
|
101
|
+
)}
|
|
102
|
+
</Card>
|
|
103
|
+
|
|
104
|
+
{!readOnly && (
|
|
105
|
+
<Flex align="flex-start" marginLeft={2}>
|
|
106
|
+
<Box style={{width: 200}}>
|
|
107
|
+
<ColorPickerFields
|
|
108
|
+
rgb={rgb}
|
|
109
|
+
hsl={hsl}
|
|
110
|
+
hex={hex}
|
|
111
|
+
onChange={onChange}
|
|
112
|
+
disableAlpha={disableAlpha}
|
|
113
|
+
/>
|
|
114
|
+
</Box>
|
|
115
|
+
<Box marginLeft={2}>
|
|
116
|
+
<Button onClick={onUnset} title="Delete color" icon={TrashIcon} tone="critical" />
|
|
117
|
+
</Box>
|
|
118
|
+
</Flex>
|
|
119
|
+
)}
|
|
120
|
+
</Flex>
|
|
121
|
+
</Stack>
|
|
122
|
+
</Card>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
ColorPicker.propTypes = {
|
|
128
|
+
width: PropTypes.string,
|
|
129
|
+
hex: PropTypes.string,
|
|
130
|
+
hsl: PropTypes.object,
|
|
131
|
+
hsv: PropTypes.object,
|
|
132
|
+
rgb: PropTypes.object,
|
|
133
|
+
onChange: PropTypes.func,
|
|
134
|
+
disableAlpha: PropTypes.bool,
|
|
135
|
+
readOnly: PropTypes.bool,
|
|
136
|
+
renderers: PropTypes.func,
|
|
137
|
+
onUnset: PropTypes.func,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ColorPicker.defaultProps = {
|
|
141
|
+
disableAlpha: false,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default ColorWrap(ColorPicker)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import * as color from 'react-color/lib/helpers/color'
|
|
3
|
+
import {EditableInput} from 'react-color/lib/components/common'
|
|
4
|
+
import {Box, Flex, useTheme} from '@sanity/ui'
|
|
5
|
+
|
|
6
|
+
export const ColorPickerFields = ({onChange, rgb, hsl, hex, disableAlpha}) => {
|
|
7
|
+
const {sanity} = useTheme()
|
|
8
|
+
|
|
9
|
+
const inputStyles = {
|
|
10
|
+
input: {
|
|
11
|
+
width: '80%',
|
|
12
|
+
padding: '4px 10% 3px',
|
|
13
|
+
border: 'none',
|
|
14
|
+
boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,
|
|
15
|
+
color: sanity.color.input.default.enabled.fg,
|
|
16
|
+
backgroundColor: sanity.color.input.default.enabled.bg,
|
|
17
|
+
fontSize: sanity.fonts.text.sizes[0].fontSize,
|
|
18
|
+
textAlign: 'center',
|
|
19
|
+
},
|
|
20
|
+
label: {
|
|
21
|
+
display: 'block',
|
|
22
|
+
textAlign: 'center',
|
|
23
|
+
fontSize: sanity.fonts.label.sizes[0].fontSize,
|
|
24
|
+
color: sanity.color.base.fg,
|
|
25
|
+
paddingTop: '3px',
|
|
26
|
+
paddingBottom: '4px',
|
|
27
|
+
textTransform: 'capitalize',
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const handleChange = (data, e) => {
|
|
32
|
+
if (data.hex && color.isValidHex(data.hex)) {
|
|
33
|
+
onChange(
|
|
34
|
+
{
|
|
35
|
+
hex: data.hex,
|
|
36
|
+
source: 'hex',
|
|
37
|
+
},
|
|
38
|
+
e
|
|
39
|
+
)
|
|
40
|
+
} else if (data.r || data.g || data.b) {
|
|
41
|
+
onChange(
|
|
42
|
+
{
|
|
43
|
+
r: data.r || rgb.r,
|
|
44
|
+
g: data.g || rgb.g,
|
|
45
|
+
b: data.b || rgb.b,
|
|
46
|
+
a: rgb.a,
|
|
47
|
+
source: 'rgb',
|
|
48
|
+
},
|
|
49
|
+
e
|
|
50
|
+
)
|
|
51
|
+
} else if (data.a) {
|
|
52
|
+
if (data.a < 0) {
|
|
53
|
+
data.a = 0
|
|
54
|
+
} else if (data.a > 100) {
|
|
55
|
+
data.a = 100
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
data.a /= 100
|
|
59
|
+
onChange(
|
|
60
|
+
{
|
|
61
|
+
h: hsl.h,
|
|
62
|
+
s: hsl.s,
|
|
63
|
+
l: hsl.l,
|
|
64
|
+
a: data.a,
|
|
65
|
+
source: 'rgb',
|
|
66
|
+
},
|
|
67
|
+
e
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<Flex>
|
|
74
|
+
<Box flex={2} marginRight={1}>
|
|
75
|
+
<EditableInput
|
|
76
|
+
style={inputStyles}
|
|
77
|
+
label="hex"
|
|
78
|
+
value={hex.replace('#', '')}
|
|
79
|
+
onChange={handleChange}
|
|
80
|
+
/>
|
|
81
|
+
</Box>
|
|
82
|
+
<Box flex={1} marginRight={1}>
|
|
83
|
+
<EditableInput
|
|
84
|
+
style={inputStyles}
|
|
85
|
+
label="r"
|
|
86
|
+
value={rgb.r}
|
|
87
|
+
onChange={handleChange}
|
|
88
|
+
dragLabel="true"
|
|
89
|
+
dragMax="255"
|
|
90
|
+
/>
|
|
91
|
+
</Box>
|
|
92
|
+
<Box flex={1} marginRight={1}>
|
|
93
|
+
<EditableInput
|
|
94
|
+
style={inputStyles}
|
|
95
|
+
label="g"
|
|
96
|
+
value={rgb.g}
|
|
97
|
+
onChange={handleChange}
|
|
98
|
+
dragLabel="true"
|
|
99
|
+
dragMax="255"
|
|
100
|
+
/>
|
|
101
|
+
</Box>
|
|
102
|
+
<Box flex={1} marginRight={1}>
|
|
103
|
+
<EditableInput
|
|
104
|
+
style={inputStyles}
|
|
105
|
+
label="b"
|
|
106
|
+
value={rgb.b}
|
|
107
|
+
onChange={handleChange}
|
|
108
|
+
dragLabel="true"
|
|
109
|
+
dragMax="255"
|
|
110
|
+
/>
|
|
111
|
+
</Box>
|
|
112
|
+
{!disableAlpha && (
|
|
113
|
+
<Box flex={1}>
|
|
114
|
+
<EditableInput
|
|
115
|
+
style={inputStyles}
|
|
116
|
+
label="a"
|
|
117
|
+
value={Math.round(rgb.a * 100)}
|
|
118
|
+
onChange={handleChange}
|
|
119
|
+
dragLabel="true"
|
|
120
|
+
dragMax="100"
|
|
121
|
+
/>
|
|
122
|
+
</Box>
|
|
123
|
+
)}
|
|
124
|
+
</Flex>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default ColorPickerFields
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-disable react/display-name */
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import ColorInput from '../ColorInput'
|
|
4
|
+
|
|
5
|
+
const round = (val) => Math.round(val * 100)
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
name: 'color',
|
|
9
|
+
type: 'object',
|
|
10
|
+
title: 'Color',
|
|
11
|
+
inputComponent: ColorInput,
|
|
12
|
+
fields: [
|
|
13
|
+
{
|
|
14
|
+
title: 'Hex',
|
|
15
|
+
name: 'hex',
|
|
16
|
+
type: 'string',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: 'Alpha',
|
|
20
|
+
name: 'alpha',
|
|
21
|
+
type: 'number',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
title: 'Hue Saturation Lightness',
|
|
25
|
+
name: 'hsl',
|
|
26
|
+
type: 'hslaColor',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: 'Hue Saturation Value',
|
|
30
|
+
name: 'hsv',
|
|
31
|
+
type: 'hsvaColor',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
title: 'Red Green Blue (rgb)',
|
|
35
|
+
name: 'rgb',
|
|
36
|
+
type: 'rgbaColor',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
preview: {
|
|
40
|
+
select: {
|
|
41
|
+
title: 'hex',
|
|
42
|
+
alpha: 'alpha',
|
|
43
|
+
hex: 'hex',
|
|
44
|
+
hsl: 'hsl',
|
|
45
|
+
},
|
|
46
|
+
prepare({title, hex, hsl, alpha}) {
|
|
47
|
+
let subtitle = hex || 'No color set'
|
|
48
|
+
if (hsl) {
|
|
49
|
+
subtitle = `H:${round(hsl.l)} S:${round(hsl.l)} L:${round(hsl.l)} A:${round(alpha)}`
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
title: title,
|
|
53
|
+
subtitle: subtitle,
|
|
54
|
+
media: () => (
|
|
55
|
+
<div
|
|
56
|
+
style={{
|
|
57
|
+
backgroundColor: hex || '#000',
|
|
58
|
+
opacity: alpha || 1,
|
|
59
|
+
position: 'absolute',
|
|
60
|
+
height: '100%',
|
|
61
|
+
width: '100%',
|
|
62
|
+
top: '0',
|
|
63
|
+
left: '0',
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
),
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
title: 'Hue Saturation Lightness',
|
|
3
|
+
name: 'hslaColor',
|
|
4
|
+
type: 'object',
|
|
5
|
+
fields: [
|
|
6
|
+
{name: 'h', type: 'number', title: 'Hue'},
|
|
7
|
+
{name: 's', type: 'number', title: 'Saturation'},
|
|
8
|
+
{name: 'l', type: 'number', title: 'Lightness'},
|
|
9
|
+
{name: 'a', type: 'number', title: 'Alpha'},
|
|
10
|
+
],
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
title: 'Hue Saturation Value',
|
|
3
|
+
name: 'hsvaColor',
|
|
4
|
+
type: 'object',
|
|
5
|
+
fields: [
|
|
6
|
+
{name: 'h', type: 'number', title: 'Hue'},
|
|
7
|
+
{name: 's', type: 'number', title: 'Saturation'},
|
|
8
|
+
{name: 'v', type: 'number', title: 'Value'},
|
|
9
|
+
{name: 'a', type: 'number', title: 'Alpha'},
|
|
10
|
+
],
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
title: 'Red Green Blue (rgb)',
|
|
3
|
+
name: 'rgbaColor',
|
|
4
|
+
type: 'object',
|
|
5
|
+
fields: [
|
|
6
|
+
{name: 'r', type: 'number', title: 'Red'},
|
|
7
|
+
{name: 'g', type: 'number', title: 'Green'},
|
|
8
|
+
{name: 'b', type: 'number', title: 'Blue'},
|
|
9
|
+
{name: 'a', type: 'number', title: 'Alpha'},
|
|
10
|
+
],
|
|
11
|
+
}
|
package/.eslintrc.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
parser: '@babel/eslint-parser',
|
|
4
|
-
globals: {
|
|
5
|
-
__DEV__: true,
|
|
6
|
-
JSX: true,
|
|
7
|
-
},
|
|
8
|
-
env: {
|
|
9
|
-
node: true,
|
|
10
|
-
browser: true,
|
|
11
|
-
},
|
|
12
|
-
settings: {
|
|
13
|
-
react: {version: '16.9.0'},
|
|
14
|
-
},
|
|
15
|
-
extends: ['sanity', 'sanity/react', 'plugin:react-hooks/recommended', 'prettier'],
|
|
16
|
-
rules: {
|
|
17
|
-
camelcase: ['error', {allow: ['^unstable_', '^Unstable_']}],
|
|
18
|
-
'prettier/prettier': 'error',
|
|
19
|
-
'react/prop-types': 'off',
|
|
20
|
-
'react/forbid-prop-types': 'off',
|
|
21
|
-
'react/jsx-no-bind': 'off',
|
|
22
|
-
'react/require-default-props': 'off',
|
|
23
|
-
},
|
|
24
|
-
plugins: ['prettier', 'react'],
|
|
25
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: CI & Release
|
|
3
|
-
|
|
4
|
-
# Workflow name based on selected inputs. Fallback to default Github naming when expression evaluates to empty string
|
|
5
|
-
run-name: >-
|
|
6
|
-
${{
|
|
7
|
-
inputs.release && inputs.test && format('Build {0} ➤ Test ➤ Publish to NPM', github.ref_name) ||
|
|
8
|
-
inputs.release && !inputs.test && format('Build {0} ➤ Skip Tests ➤ Publish to NPM', github.ref_name) ||
|
|
9
|
-
github.event_name == 'workflow_dispatch' && inputs.test && format('Build {0} ➤ Test', github.ref_name) ||
|
|
10
|
-
github.event_name == 'workflow_dispatch' && !inputs.test && format('Build {0} ➤ Skip Tests', github.ref_name) ||
|
|
11
|
-
''
|
|
12
|
-
}}
|
|
13
|
-
|
|
14
|
-
on:
|
|
15
|
-
# Build on pushes branches that have a PR (including drafts)
|
|
16
|
-
pull_request:
|
|
17
|
-
# Build on commits pushed to branches without a PR if it's in the allowlist
|
|
18
|
-
push:
|
|
19
|
-
branches: [main,studio-v2]
|
|
20
|
-
# https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
|
|
21
|
-
workflow_dispatch:
|
|
22
|
-
inputs:
|
|
23
|
-
test:
|
|
24
|
-
description: Run tests
|
|
25
|
-
required: true
|
|
26
|
-
default: true
|
|
27
|
-
type: boolean
|
|
28
|
-
release:
|
|
29
|
-
description: Release new version
|
|
30
|
-
required: true
|
|
31
|
-
default: false
|
|
32
|
-
type: boolean
|
|
33
|
-
|
|
34
|
-
concurrency:
|
|
35
|
-
# On PRs builds will cancel if new pushes happen before the CI completes, as it defines `github.head_ref` and gives it the name of the branch the PR wants to merge into
|
|
36
|
-
# Otherwise `github.run_id` ensures that you can quickly merge a queue of PRs without causing tests to auto cancel on any of the commits pushed to main.
|
|
37
|
-
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
38
|
-
cancel-in-progress: true
|
|
39
|
-
|
|
40
|
-
jobs:
|
|
41
|
-
log-the-inputs:
|
|
42
|
-
name: Log inputs
|
|
43
|
-
runs-on: ubuntu-latest
|
|
44
|
-
steps:
|
|
45
|
-
- run: |
|
|
46
|
-
echo "Inputs: $INPUTS"
|
|
47
|
-
env:
|
|
48
|
-
INPUTS: ${{ toJSON(inputs) }}
|
|
49
|
-
|
|
50
|
-
build:
|
|
51
|
-
runs-on: ubuntu-latest
|
|
52
|
-
name: Lint & Build
|
|
53
|
-
steps:
|
|
54
|
-
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
|
|
55
|
-
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
|
|
56
|
-
with:
|
|
57
|
-
cache: npm
|
|
58
|
-
node-version: lts/*
|
|
59
|
-
- run: npm ci
|
|
60
|
-
# Linting can be skipped
|
|
61
|
-
- run: npm run lint --if-present
|
|
62
|
-
if: github.event.inputs.test != 'false'
|
|
63
|
-
# But not the build script, as semantic-release will crash if this command fails so it makes sense to test it early
|
|
64
|
-
- run: npm run prepublishOnly --if-present
|
|
65
|
-
|
|
66
|
-
# test:
|
|
67
|
-
# needs: build
|
|
68
|
-
# # The test matrix can be skipped, in case a new release needs to be fast-tracked and tests are already passing on main
|
|
69
|
-
# if: github.event.inputs.test != 'false'
|
|
70
|
-
# runs-on: ${{ matrix.os }}
|
|
71
|
-
# name: Node.js ${{ matrix.node }} / ${{ matrix.os }}
|
|
72
|
-
# strategy:
|
|
73
|
-
# # A test failing on windows doesn't mean it'll fail on macos. It's useful to let all tests run to its completion to get the full picture
|
|
74
|
-
# fail-fast: false
|
|
75
|
-
# matrix:
|
|
76
|
-
# # Run the testing suite on each major OS with the latest LTS release of Node.js
|
|
77
|
-
# os: [macos-latest, ubuntu-latest, windows-latest]
|
|
78
|
-
# node: [lts/*]
|
|
79
|
-
# # It makes sense to also test the oldest, and latest, versions of Node.js, on ubuntu-only since it's the fastest CI runner
|
|
80
|
-
# include:
|
|
81
|
-
# - os: ubuntu-latest
|
|
82
|
-
# # Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
|
|
83
|
-
# node: lts/-2
|
|
84
|
-
# - os: ubuntu-latest
|
|
85
|
-
# # Test the actively developed version that will become the latest LTS release next October
|
|
86
|
-
# node: current
|
|
87
|
-
# steps:
|
|
88
|
-
# # It's only necessary to do this for windows, as mac and ubuntu are sane OS's that already use LF
|
|
89
|
-
# - name: Set git to use LF
|
|
90
|
-
# if: matrix.os == 'windows-latest'
|
|
91
|
-
# run: |
|
|
92
|
-
# git config --global core.autocrlf false
|
|
93
|
-
# git config --global core.eol lf
|
|
94
|
-
# - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
|
|
95
|
-
# - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
|
|
96
|
-
# with:
|
|
97
|
-
# cache: npm
|
|
98
|
-
# node-version: ${{ matrix.node }}
|
|
99
|
-
# - run: npm i
|
|
100
|
-
# - run: npm test --if-present
|
|
101
|
-
|
|
102
|
-
release:
|
|
103
|
-
# needs: [build, test]
|
|
104
|
-
needs: [build]
|
|
105
|
-
# only run if opt-in during workflow_dispatch
|
|
106
|
-
if: always() && github.event.inputs.release == 'true' && needs.build.result != 'failure' && needs.test.result != 'failure' && needs.test.result != 'cancelled'
|
|
107
|
-
runs-on: ubuntu-latest
|
|
108
|
-
name: Semantic release
|
|
109
|
-
steps:
|
|
110
|
-
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
|
|
111
|
-
with:
|
|
112
|
-
# Need to fetch entire commit history to
|
|
113
|
-
# analyze every commit since last release
|
|
114
|
-
fetch-depth: 0
|
|
115
|
-
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
|
|
116
|
-
with:
|
|
117
|
-
cache: npm
|
|
118
|
-
node-version: lts/*
|
|
119
|
-
- run: npm ci
|
|
120
|
-
# Branches that will release new versions are defined in .releaserc.json
|
|
121
|
-
- run: npx semantic-release
|
|
122
|
-
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
|
|
123
|
-
# e.g. git tags were pushed but it exited before `npm publish`
|
|
124
|
-
if: always()
|
|
125
|
-
env:
|
|
126
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
127
|
-
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
|
128
|
-
# Re-run semantic release with rich logs if it failed to publish for easier debugging
|
|
129
|
-
- run: npx semantic-release --dry-run --debug
|
|
130
|
-
if: failure()
|
|
131
|
-
env:
|
|
132
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
133
|
-
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
package/.husky/commit-msg
DELETED
package/.husky/pre-commit
DELETED
package/.prettierrc
DELETED
package/.releaserc.json
DELETED
|
Binary file
|
package/CHANGELOG.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!-- markdownlint-disable --><!-- textlint-disable -->
|
|
2
|
-
|
|
3
|
-
# 📓 Changelog
|
|
4
|
-
|
|
5
|
-
All notable changes to this project will be documented in this file. See
|
|
6
|
-
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
|
-
|
|
8
|
-
## [2.36.0-v2-studio.1](https://github.com/sanity-io/color-input/compare/v2.35.2...v2.36.0-v2-studio.1) (2022-11-23)
|
|
9
|
-
|
|
10
|
-
### Features
|
|
11
|
-
|
|
12
|
-
- @sanity/color-input (standalone) for Sanity Studio v2 ([d3a8655](https://github.com/sanity-io/color-input/commit/d3a8655747e6e52c4f09486ea7970b029f80b860))
|
package/assets/color-input.png
DELETED
|
Binary file
|
package/assets/no-alpha.png
DELETED
|
Binary file
|
package/commitlint.config.js
DELETED
package/lint-staged.config.js
DELETED