@strapi/plugin-color-picker 0.0.0-next.aea0ea8350c9137c507bb25fe03460680fdbeec1 → 0.0.0-next.b31c3c3f6d934ebbb3d64cbf9722d8f50efc0391
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/admin/src/components/ColorPicker/ColorPickerIcon/index.js +3 -2
- package/admin/src/components/ColorPicker/ColorPickerInput/index.js +123 -114
- package/admin/src/components/tests/color-picker-input.test.js +3 -1
- package/admin/src/hooks/useComposeRefs.js +48 -0
- package/admin/src/index.js +2 -1
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +7 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/register.d.ts +1 -0
- package/dist/server/register.js +12 -0
- package/dist/server/register.js.map +1 -0
- package/package.json +17 -6
- package/strapi-server.js +1 -1
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -14
- package/color-picker.png +0 -0
- package/jest.config.front.js +0 -6
- package/server/index.js +0 -7
- package/server/register.js +0 -9
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
|
|
3
|
+
import { Flex, Icon } from '@strapi/design-system';
|
|
4
4
|
import { Paint } from '@strapi/icons';
|
|
5
|
+
import styled from 'styled-components';
|
|
5
6
|
|
|
6
7
|
const IconBox = styled(Flex)`
|
|
7
8
|
/* Hard code color values */
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
import styled from 'styled-components';
|
|
1
|
+
import React, { forwardRef, useRef, useState } from 'react';
|
|
2
|
+
|
|
4
3
|
import {
|
|
5
|
-
Typography,
|
|
6
|
-
Flex,
|
|
7
|
-
Box,
|
|
8
4
|
BaseButton,
|
|
9
|
-
|
|
5
|
+
Box,
|
|
10
6
|
Field,
|
|
11
|
-
FieldHint,
|
|
12
7
|
FieldError,
|
|
13
|
-
|
|
8
|
+
FieldHint,
|
|
14
9
|
FieldInput,
|
|
10
|
+
FieldLabel,
|
|
11
|
+
Flex,
|
|
12
|
+
FocusTrap,
|
|
15
13
|
Popover,
|
|
14
|
+
Typography,
|
|
16
15
|
} from '@strapi/design-system';
|
|
17
16
|
import { CarretDown } from '@strapi/icons';
|
|
18
|
-
import
|
|
17
|
+
import PropTypes from 'prop-types';
|
|
19
18
|
import { HexColorPicker } from 'react-colorful';
|
|
19
|
+
import { useIntl } from 'react-intl';
|
|
20
|
+
import styled from 'styled-components';
|
|
20
21
|
|
|
22
|
+
import { useComposedRefs } from '../../../hooks/useComposeRefs';
|
|
21
23
|
import getTrad from '../../../utils/getTrad';
|
|
22
24
|
|
|
23
25
|
const ColorPreview = styled.div`
|
|
@@ -73,112 +75,119 @@ const ColorPickerPopover = styled(Popover)`
|
|
|
73
75
|
min-height: 270px;
|
|
74
76
|
`;
|
|
75
77
|
|
|
76
|
-
const ColorPickerInput = (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
})}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
variant="omega"
|
|
132
|
-
>
|
|
133
|
-
{color}
|
|
134
|
-
</Typography>
|
|
135
|
-
</Flex>
|
|
136
|
-
<CarretDown aria-hidden />
|
|
137
|
-
</ColorPickerToggle>
|
|
138
|
-
{showColorPicker && (
|
|
139
|
-
<ColorPickerPopover
|
|
140
|
-
onBlur={handleBlur}
|
|
141
|
-
role="dialog"
|
|
142
|
-
source={colorPickerButtonRef}
|
|
143
|
-
spacing={4}
|
|
78
|
+
const ColorPickerInput = forwardRef(
|
|
79
|
+
(
|
|
80
|
+
{
|
|
81
|
+
attribute,
|
|
82
|
+
description,
|
|
83
|
+
disabled,
|
|
84
|
+
error,
|
|
85
|
+
intlLabel,
|
|
86
|
+
labelAction,
|
|
87
|
+
name,
|
|
88
|
+
onChange,
|
|
89
|
+
required,
|
|
90
|
+
value,
|
|
91
|
+
},
|
|
92
|
+
forwardedRef
|
|
93
|
+
) => {
|
|
94
|
+
const [showColorPicker, setShowColorPicker] = useState(false);
|
|
95
|
+
const colorPickerButtonRef = useRef();
|
|
96
|
+
const { formatMessage } = useIntl();
|
|
97
|
+
const color = value || '#000000';
|
|
98
|
+
const styleUppercase = { textTransform: 'uppercase' };
|
|
99
|
+
|
|
100
|
+
const handleBlur = (e) => {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
|
|
103
|
+
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
104
|
+
setShowColorPicker(false);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const composedRefs = useComposedRefs(forwardedRef, colorPickerButtonRef);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Field
|
|
112
|
+
name={name}
|
|
113
|
+
id={name}
|
|
114
|
+
// GenericInput calls formatMessage and returns a string for the error
|
|
115
|
+
error={error}
|
|
116
|
+
hint={description && formatMessage(description)}
|
|
117
|
+
required={required}
|
|
118
|
+
>
|
|
119
|
+
<Flex direction="column" alignItems="stretch" gap={1}>
|
|
120
|
+
<FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel>
|
|
121
|
+
<ColorPickerToggle
|
|
122
|
+
ref={composedRefs}
|
|
123
|
+
aria-label={formatMessage({
|
|
124
|
+
id: getTrad('color-picker.toggle.aria-label'),
|
|
125
|
+
defaultMessage: 'Color picker toggle',
|
|
126
|
+
})}
|
|
127
|
+
aria-controls="color-picker-value"
|
|
128
|
+
aria-haspopup="dialog"
|
|
129
|
+
aria-expanded={showColorPicker}
|
|
130
|
+
aria-disabled={disabled}
|
|
131
|
+
disabled={disabled}
|
|
132
|
+
onClick={() => setShowColorPicker(!showColorPicker)}
|
|
144
133
|
>
|
|
145
|
-
<
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
onChange={onChange}
|
|
134
|
+
<Flex>
|
|
135
|
+
<ColorPreview color={color} />
|
|
136
|
+
<Typography
|
|
137
|
+
style={styleUppercase}
|
|
138
|
+
textColor={value ? null : 'neutral600'}
|
|
139
|
+
variant="omega"
|
|
140
|
+
>
|
|
141
|
+
{color}
|
|
142
|
+
</Typography>
|
|
143
|
+
</Flex>
|
|
144
|
+
<CarretDown aria-hidden />
|
|
145
|
+
</ColorPickerToggle>
|
|
146
|
+
{showColorPicker && (
|
|
147
|
+
<ColorPickerPopover
|
|
148
|
+
onBlur={handleBlur}
|
|
149
|
+
role="dialog"
|
|
150
|
+
source={colorPickerButtonRef}
|
|
151
|
+
spacing={4}
|
|
152
|
+
>
|
|
153
|
+
<FocusTrap onEscape={() => setShowColorPicker(false)}>
|
|
154
|
+
<ColorPicker
|
|
155
|
+
color={color}
|
|
156
|
+
onChange={(hexValue) =>
|
|
157
|
+
onChange({ target: { name, value: hexValue, type: attribute.type } })
|
|
158
|
+
}
|
|
171
159
|
/>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
160
|
+
<Flex paddingTop={3} paddingLeft={4} justifyContent="flex-end">
|
|
161
|
+
<Box paddingRight={2}>
|
|
162
|
+
<Typography variant="omega" as="label" textColor="neutral600">
|
|
163
|
+
{formatMessage({
|
|
164
|
+
id: getTrad('color-picker.input.format'),
|
|
165
|
+
defaultMessage: 'HEX',
|
|
166
|
+
})}
|
|
167
|
+
</Typography>
|
|
168
|
+
</Box>
|
|
169
|
+
<FieldInput
|
|
170
|
+
id="color-picker-value"
|
|
171
|
+
aria-label={formatMessage({
|
|
172
|
+
id: getTrad('color-picker.input.aria-label'),
|
|
173
|
+
defaultMessage: 'Color picker input',
|
|
174
|
+
})}
|
|
175
|
+
style={styleUppercase}
|
|
176
|
+
value={value}
|
|
177
|
+
placeholder="#000000"
|
|
178
|
+
onChange={onChange}
|
|
179
|
+
/>
|
|
180
|
+
</Flex>
|
|
181
|
+
</FocusTrap>
|
|
182
|
+
</ColorPickerPopover>
|
|
183
|
+
)}
|
|
184
|
+
<FieldHint />
|
|
185
|
+
<FieldError />
|
|
186
|
+
</Flex>
|
|
187
|
+
</Field>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
);
|
|
182
191
|
|
|
183
192
|
ColorPickerInput.defaultProps = {
|
|
184
193
|
description: null,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { lightTheme, ThemeProvider } from '@strapi/design-system';
|
|
4
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
4
5
|
import { IntlProvider } from 'react-intl';
|
|
6
|
+
|
|
5
7
|
import ColorPickerInput from '../ColorPicker/ColorPickerInput';
|
|
6
8
|
|
|
7
9
|
const mockAttribute = {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Set a given ref to a given value
|
|
5
|
+
* This utility takes care of different types of refs: callback refs and RefObject(s)
|
|
6
|
+
*/
|
|
7
|
+
function setRef(ref, value) {
|
|
8
|
+
if (typeof ref === 'function') {
|
|
9
|
+
ref(value);
|
|
10
|
+
} else if (ref !== null && ref !== undefined) {
|
|
11
|
+
ref.current = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A utility to compose multiple refs together
|
|
17
|
+
* Accepts callback refs and RefObject(s)
|
|
18
|
+
*/
|
|
19
|
+
function composeRefs(...refs) {
|
|
20
|
+
return (node) => refs.forEach((ref) => setRef(ref, node));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Takes multiple React like refs either React.Ref or a callback:
|
|
25
|
+
* (node: T) => void and returns a single function that can be
|
|
26
|
+
* passed to a React component as a ref.
|
|
27
|
+
*
|
|
28
|
+
* Example:
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { useComposedRefs } from '../hooks/useComposedRefs';
|
|
31
|
+
*
|
|
32
|
+
* const Component = React.forwardRef<HTMLInputElement, ComponentProps>((props, forwardedRef) => {
|
|
33
|
+
* const ref = useComposedRefs(internalRef, forwardedRef);
|
|
34
|
+
*
|
|
35
|
+
* React.useEffect(() => {
|
|
36
|
+
* ref.current.focus();
|
|
37
|
+
* }, [ref]);
|
|
38
|
+
*
|
|
39
|
+
* return <input ref={ref} />
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
function useComposedRefs(...refs) {
|
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { composeRefs, useComposedRefs };
|
package/admin/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import ColorPickerIcon from './components/ColorPicker/ColorPickerIcon';
|
|
4
|
+
import pluginId from './pluginId';
|
|
4
5
|
import getTrad from './utils/getTrad';
|
|
5
6
|
|
|
6
7
|
export default {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/src/index.ts"],"names":[],"mappings":";;AAAA,yCAAsC;AAEtC,kBAAe;IACb,QAAQ,EAAR,mBAAQ;CACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const register: ({ strapi }: any) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const register = ({ strapi }) => {
|
|
5
|
+
strapi.customFields.register({
|
|
6
|
+
name: 'color',
|
|
7
|
+
plugin: 'color-picker',
|
|
8
|
+
type: 'string',
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
exports.register = register;
|
|
12
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../server/src/register.ts"],"names":[],"mappings":";;;AAAO,MAAM,QAAQ,GAAG,CAAC,EAAE,MAAM,EAAO,EAAE,EAAE;IAC1C,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC;QAC3B,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,cAAc;QACtB,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,QAAQ,YAMnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-color-picker",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.b31c3c3f6d934ebbb3d64cbf9722d8f50efc0391",
|
|
4
4
|
"description": "Strapi maintained Custom Fields",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"name": "color-picker",
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"displayName": "Color Picker"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@strapi/design-system": "1.
|
|
13
|
-
"@strapi/helper-plugin": "0.0.0-next.
|
|
14
|
-
"@strapi/icons": "1.
|
|
12
|
+
"@strapi/design-system": "1.9.0",
|
|
13
|
+
"@strapi/helper-plugin": "0.0.0-next.b31c3c3f6d934ebbb3d64cbf9722d8f50efc0391",
|
|
14
|
+
"@strapi/icons": "1.9.0",
|
|
15
15
|
"prop-types": "^15.8.1",
|
|
16
16
|
"react-colorful": "5.6.1",
|
|
17
17
|
"react-intl": "6.4.1"
|
|
@@ -30,7 +30,18 @@
|
|
|
30
30
|
"react-router-dom": "5.3.4",
|
|
31
31
|
"styled-components": "5.3.3"
|
|
32
32
|
},
|
|
33
|
+
"files": [
|
|
34
|
+
"./dist",
|
|
35
|
+
"./admin",
|
|
36
|
+
"strapi-admin.js",
|
|
37
|
+
"strapi-server.js"
|
|
38
|
+
],
|
|
33
39
|
"scripts": {
|
|
40
|
+
"build": "run -T tsc -p server/tsconfig.json --outDir ./dist/server",
|
|
41
|
+
"build:ts": "run build",
|
|
42
|
+
"watch": "run -T tsc -w --preserveWatchOutput",
|
|
43
|
+
"clean": "run -T rimraf ./dist",
|
|
44
|
+
"prepublishOnly": "yarn clean && yarn build",
|
|
34
45
|
"test:front": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js",
|
|
35
46
|
"test:front:watch": "run -T cross-env IS_EE=true jest --config ./jest.config.front.js --watchAll",
|
|
36
47
|
"test:front:ce": "run -T cross-env IS_EE=false jest --config ./jest.config.front.js",
|
|
@@ -56,8 +67,8 @@
|
|
|
56
67
|
}
|
|
57
68
|
],
|
|
58
69
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
70
|
+
"node": ">=16.0.0 <=20.x.x",
|
|
60
71
|
"npm": ">=6.0.0"
|
|
61
72
|
},
|
|
62
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "b31c3c3f6d934ebbb3d64cbf9722d8f50efc0391"
|
|
63
74
|
}
|
package/strapi-server.js
CHANGED
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
package/color-picker.png
DELETED
|
Binary file
|
package/jest.config.front.js
DELETED
package/server/index.js
DELETED