@strapi/plugin-color-picker 0.0.0-next.9b56e4f83804383c185d8178fc8a6d9851327a0c → 0.0.0-next.a2b1a1e72400fea121da3c3fb18f524b0c885ba8

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.
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
- import styled from 'styled-components';
3
- import { Icon, Flex } from '@strapi/design-system';
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, { useState, useRef } from 'react';
2
- import PropTypes from 'prop-types';
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
- FocusTrap,
5
+ Box,
10
6
  Field,
11
- FieldHint,
12
7
  FieldError,
13
- FieldLabel,
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 { useIntl } from 'react-intl';
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
- attribute,
78
- description,
79
- disabled,
80
- error,
81
- intlLabel,
82
- labelAction,
83
- name,
84
- onChange,
85
- required,
86
- value,
87
- }) => {
88
- const [showColorPicker, setShowColorPicker] = useState(false);
89
- const colorPickerButtonRef = useRef();
90
- const { formatMessage } = useIntl();
91
- const color = value || '#000000';
92
- const styleUppercase = { textTransform: 'uppercase' };
93
-
94
- const handleBlur = (e) => {
95
- e.preventDefault();
96
-
97
- if (!e.currentTarget.contains(e.relatedTarget)) {
98
- setShowColorPicker(false);
99
- }
100
- };
101
-
102
- return (
103
- <Field
104
- name={name}
105
- id={name}
106
- // GenericInput calls formatMessage and returns a string for the error
107
- error={error}
108
- hint={description && formatMessage(description)}
109
- required={required}
110
- >
111
- <Flex direction="column" alignItems="stretch" gap={1}>
112
- <FieldLabel action={labelAction}>{formatMessage(intlLabel)}</FieldLabel>
113
- <ColorPickerToggle
114
- ref={colorPickerButtonRef}
115
- aria-label={formatMessage({
116
- id: getTrad('color-picker.toggle.aria-label'),
117
- defaultMessage: 'Color picker toggle',
118
- })}
119
- aria-controls="color-picker-value"
120
- aria-haspopup="dialog"
121
- aria-expanded={showColorPicker}
122
- aria-disabled={disabled}
123
- disabled={disabled}
124
- onClick={() => setShowColorPicker(!showColorPicker)}
125
- >
126
- <Flex>
127
- <ColorPreview color={color} />
128
- <Typography
129
- style={styleUppercase}
130
- textColor={value ? null : 'neutral600'}
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
- <FocusTrap onEscape={() => setShowColorPicker(false)}>
146
- <ColorPicker
147
- color={color}
148
- onChange={(hexValue) =>
149
- onChange({ target: { name, value: hexValue, type: attribute.type } })
150
- }
151
- />
152
- <Flex paddingTop={3} paddingLeft={4} justifyContent="flex-end">
153
- <Box paddingRight={2}>
154
- <Typography variant="omega" as="label" textColor="neutral600">
155
- {formatMessage({
156
- id: getTrad('color-picker.input.format'),
157
- defaultMessage: 'HEX',
158
- })}
159
- </Typography>
160
- </Box>
161
- <FieldInput
162
- id="color-picker-value"
163
- aria-label={formatMessage({
164
- id: getTrad('color-picker.input.aria-label'),
165
- defaultMessage: 'Color picker input',
166
- })}
167
- style={styleUppercase}
168
- value={value}
169
- placeholder="#000000"
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
- </Flex>
173
- </FocusTrap>
174
- </ColorPickerPopover>
175
- )}
176
- <FieldHint />
177
- <FieldError />
178
- </Flex>
179
- </Field>
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,13 +1,16 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`<ColorPickerInput /> renders and matches the snapshot 1`] = `
4
- .c3 {
5
- background: #ffffff;
6
- padding: 8px;
7
- border-radius: 4px;
8
- border-color: #dcdce4;
9
- border: 1px solid #dcdce4;
10
- cursor: pointer;
4
+ .c9 {
5
+ border: 0;
6
+ -webkit-clip: rect(0 0 0 0);
7
+ clip: rect(0 0 0 0);
8
+ height: 1px;
9
+ margin: -1px;
10
+ overflow: hidden;
11
+ padding: 0;
12
+ position: absolute;
13
+ width: 1px;
11
14
  }
12
15
 
13
16
  .c1 {
@@ -23,6 +26,15 @@ exports[`<ColorPickerInput /> renders and matches the snapshot 1`] = `
23
26
  color: #666687;
24
27
  }
25
28
 
29
+ .c3 {
30
+ background: #ffffff;
31
+ padding: 8px;
32
+ border-radius: 4px;
33
+ border-color: #dcdce4;
34
+ border: 1px solid #dcdce4;
35
+ cursor: pointer;
36
+ }
37
+
26
38
  .c0 {
27
39
  -webkit-align-items: stretch;
28
40
  -webkit-box-align: stretch;
@@ -101,18 +113,6 @@ exports[`<ColorPickerInput /> renders and matches the snapshot 1`] = `
101
113
  border: 2px solid #4945ff;
102
114
  }
103
115
 
104
- .c9 {
105
- border: 0;
106
- -webkit-clip: rect(0 0 0 0);
107
- clip: rect(0 0 0 0);
108
- height: 1px;
109
- margin: -1px;
110
- overflow: hidden;
111
- padding: 0;
112
- position: absolute;
113
- width: 1px;
114
- }
115
-
116
116
  .c2 {
117
117
  display: -webkit-box;
118
118
  display: -webkit-flex;
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
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 };
@@ -1,6 +1,7 @@
1
1
  import { prefixPluginTranslations } from '@strapi/helper-plugin';
2
- import pluginId from './pluginId';
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,4 @@
1
+ declare const _default: {
2
+ register: ({ strapi }: any) => void;
3
+ };
4
+ export default _default;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const register_1 = require("./register");
4
+ exports.default = {
5
+ register: register_1.register,
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -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.9b56e4f83804383c185d8178fc8a6d9851327a0c",
3
+ "version": "0.0.0-next.a2b1a1e72400fea121da3c3fb18f524b0c885ba8",
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.7.10",
13
- "@strapi/helper-plugin": "0.0.0-next.9b56e4f83804383c185d8178fc8a6d9851327a0c",
14
- "@strapi/icons": "1.7.10",
12
+ "@strapi/design-system": "1.9.0",
13
+ "@strapi/helper-plugin": "0.0.0-next.a2b1a1e72400fea121da3c3fb18f524b0c885ba8",
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": ">=14.19.1 <=18.x.x",
70
+ "node": ">=16.0.0 <=20.x.x",
60
71
  "npm": ">=6.0.0"
61
72
  },
62
- "gitHead": "9b56e4f83804383c185d8178fc8a6d9851327a0c"
73
+ "gitHead": "a2b1a1e72400fea121da3c3fb18f524b0c885ba8"
63
74
  }
package/strapi-server.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict';
2
2
 
3
- module.exports = require('./server');
3
+ module.exports = require('./dist/server');
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules/
2
- .eslintrc.js
package/.eslintrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- overrides: [
4
- {
5
- files: ['admin/**/*'],
6
- extends: ['custom/front'],
7
- },
8
- {
9
- files: ['**/*'],
10
- excludedFiles: ['admin/**/*'],
11
- extends: ['custom/back'],
12
- },
13
- ],
14
- };
package/color-picker.png DELETED
Binary file
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- preset: '../../../jest-preset.front.js',
5
- displayName: 'Color picker plugin',
6
- };
package/server/index.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- const register = require('./register');
4
-
5
- module.exports = {
6
- register,
7
- };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = ({ strapi }) => {
4
- strapi.customFields.register({
5
- name: 'color',
6
- plugin: 'color-picker',
7
- type: 'string',
8
- });
9
- };