@strapi/plugin-color-picker 0.0.0-next.e9bb5ccdc459f4c6b6717a2d5d86359b7a47d47d → 0.0.0-next.ea6e3b80ab37f554da4f8bde08dbfe9b57400d31

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.
Files changed (67) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/ColorPickerInput-B07RliGP.js +153 -0
  3. package/dist/_chunks/ColorPickerInput-B07RliGP.js.map +1 -0
  4. package/dist/_chunks/ColorPickerInput-CMg-0_-G.mjs +134 -0
  5. package/dist/_chunks/ColorPickerInput-CMg-0_-G.mjs.map +1 -0
  6. package/dist/_chunks/cs-CKl0OyEH.js +16 -0
  7. package/dist/_chunks/cs-CKl0OyEH.js.map +1 -0
  8. package/{admin/src/translations/cs.json → dist/_chunks/cs-DMmE6LK7.mjs} +6 -2
  9. package/dist/_chunks/cs-DMmE6LK7.mjs.map +1 -0
  10. package/{admin/src/translations/en.json → dist/_chunks/en-BlDau3us.mjs} +6 -2
  11. package/dist/_chunks/en-BlDau3us.mjs.map +1 -0
  12. package/dist/_chunks/en-Ct0C5cA2.js +19 -0
  13. package/dist/_chunks/en-Ct0C5cA2.js.map +1 -0
  14. package/dist/_chunks/index-B9LkgZbo.mjs +121 -0
  15. package/dist/_chunks/index-B9LkgZbo.mjs.map +1 -0
  16. package/dist/_chunks/index-BeQLcDEb.js +120 -0
  17. package/dist/_chunks/index-BeQLcDEb.js.map +1 -0
  18. package/dist/_chunks/ru-Wrg-npZz.js +19 -0
  19. package/dist/_chunks/ru-Wrg-npZz.js.map +1 -0
  20. package/{admin/src/translations/ru.json → dist/_chunks/ru-aOnA-eym.mjs} +6 -2
  21. package/dist/_chunks/ru-aOnA-eym.mjs.map +1 -0
  22. package/{admin/src/translations/sv.json → dist/_chunks/sv-BaFDND79.mjs} +6 -2
  23. package/dist/_chunks/sv-BaFDND79.mjs.map +1 -0
  24. package/dist/_chunks/sv-CKY6es_6.js +16 -0
  25. package/dist/_chunks/sv-CKY6es_6.js.map +1 -0
  26. package/{admin/src/translations/tr.json → dist/_chunks/tr-CHHW_hYI.mjs} +6 -2
  27. package/dist/_chunks/tr-CHHW_hYI.mjs.map +1 -0
  28. package/dist/_chunks/tr-DcLzQS-J.js +16 -0
  29. package/dist/_chunks/tr-DcLzQS-J.js.map +1 -0
  30. package/{admin/src/translations/zh.json → dist/_chunks/zh-DBH6uCXb.mjs} +6 -2
  31. package/dist/_chunks/zh-DBH6uCXb.mjs.map +1 -0
  32. package/dist/_chunks/zh-T5cJzhPD.js +16 -0
  33. package/dist/_chunks/zh-T5cJzhPD.js.map +1 -0
  34. package/dist/admin/index.js +4 -0
  35. package/dist/admin/index.js.map +1 -0
  36. package/dist/admin/index.mjs +5 -0
  37. package/dist/admin/index.mjs.map +1 -0
  38. package/dist/admin/src/components/ColorPickerIcon.d.ts +1 -0
  39. package/dist/admin/src/components/ColorPickerInput.d.ts +7 -0
  40. package/dist/admin/src/index.d.ts +18 -0
  41. package/dist/admin/src/pluginId.d.ts +1 -0
  42. package/dist/admin/src/utils/getTrad.d.ts +1 -0
  43. package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
  44. package/dist/server/index.js +13 -0
  45. package/dist/server/index.js.map +1 -0
  46. package/dist/server/index.mjs +14 -0
  47. package/dist/server/index.mjs.map +1 -0
  48. package/dist/server/src/index.d.ts +5 -0
  49. package/dist/server/src/index.d.ts.map +1 -0
  50. package/dist/server/src/register.d.ts +2 -0
  51. package/dist/server/src/register.d.ts.map +1 -0
  52. package/package.json +65 -38
  53. package/.eslintignore +0 -2
  54. package/.eslintrc.js +0 -14
  55. package/admin/src/components/ColorPicker/ColorPickerIcon/index.js +0 -25
  56. package/admin/src/components/ColorPicker/ColorPickerInput/index.js +0 -205
  57. package/admin/src/components/tests/__snapshots__/color-picker-input.test.js.snap +0 -238
  58. package/admin/src/components/tests/color-picker-input.test.js +0 -63
  59. package/admin/src/index.js +0 -87
  60. package/admin/src/pluginId.js +0 -5
  61. package/admin/src/utils/getTrad.js +0 -5
  62. package/color-picker.png +0 -0
  63. package/jest.config.front.js +0 -6
  64. package/server/index.js +0 -7
  65. package/server/register.js +0 -9
  66. package/strapi-admin.js +0 -3
  67. package/strapi-server.js +0 -3
@@ -1,205 +0,0 @@
1
- import React, { useState, useRef } from 'react';
2
- import PropTypes from 'prop-types';
3
- import styled from 'styled-components';
4
- import {
5
- Typography,
6
- Flex,
7
- Box,
8
- BaseButton,
9
- FocusTrap,
10
- Field,
11
- FieldHint,
12
- FieldError,
13
- FieldLabel,
14
- FieldInput,
15
- Popover,
16
- } from '@strapi/design-system';
17
- import { CarretDown } from '@strapi/icons';
18
- import { useIntl } from 'react-intl';
19
- import { HexColorPicker } from 'react-colorful';
20
-
21
- import getTrad from '../../../utils/getTrad';
22
-
23
- const ColorPreview = styled.div`
24
- border-radius: 50%;
25
- width: 20px;
26
- height: 20px;
27
- margin-right: 10px;
28
- background-color: ${(props) => props.color};
29
- border: 1px solid rgba(0, 0, 0, 0.1);
30
- `;
31
-
32
- const ColorPicker = styled(HexColorPicker)`
33
- && {
34
- width: 100%;
35
- aspect-ratio: 1.5;
36
- }
37
-
38
- .react-colorful__pointer {
39
- width: ${({ theme }) => theme.spaces[3]};
40
- height: ${({ theme }) => theme.spaces[3]};
41
- }
42
-
43
- .react-colorful__saturation {
44
- border-radius: ${({ theme }) => theme.spaces[1]};
45
- border-bottom: none;
46
- }
47
-
48
- .react-colorful__hue {
49
- border-radius: 10px;
50
- height: ${({ theme }) => theme.spaces[3]};
51
- margin-top: ${({ theme }) => theme.spaces[2]};
52
- }
53
- `;
54
-
55
- const ColorPickerToggle = styled(BaseButton)`
56
- display: flex;
57
- justify-content: space-between;
58
- align-items: center;
59
-
60
- svg {
61
- width: ${({ theme }) => theme.spaces[2]};
62
- height: ${({ theme }) => theme.spaces[2]};
63
- }
64
-
65
- svg > path {
66
- fill: ${({ theme }) => theme.colors.neutral500};
67
- justify-self: flex-end;
68
- }
69
- `;
70
-
71
- const ColorPickerPopover = styled(Popover)`
72
- padding: ${({ theme }) => theme.spaces[2]};
73
- min-height: 270px;
74
- `;
75
-
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}
144
- >
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}
171
- />
172
- </Flex>
173
- </FocusTrap>
174
- </ColorPickerPopover>
175
- )}
176
- <FieldHint />
177
- <FieldError />
178
- </Flex>
179
- </Field>
180
- );
181
- };
182
-
183
- ColorPickerInput.defaultProps = {
184
- description: null,
185
- disabled: false,
186
- error: null,
187
- labelAction: null,
188
- required: false,
189
- value: '',
190
- };
191
-
192
- ColorPickerInput.propTypes = {
193
- intlLabel: PropTypes.object.isRequired,
194
- onChange: PropTypes.func.isRequired,
195
- attribute: PropTypes.object.isRequired,
196
- name: PropTypes.string.isRequired,
197
- description: PropTypes.object,
198
- disabled: PropTypes.bool,
199
- error: PropTypes.string,
200
- labelAction: PropTypes.object,
201
- required: PropTypes.bool,
202
- value: PropTypes.string,
203
- };
204
-
205
- export default ColorPickerInput;
@@ -1,238 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
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;
11
- }
12
-
13
- .c1 {
14
- font-size: 0.75rem;
15
- line-height: 1.33;
16
- font-weight: 600;
17
- color: #32324d;
18
- }
19
-
20
- .c8 {
21
- font-size: 0.875rem;
22
- line-height: 1.43;
23
- color: #666687;
24
- }
25
-
26
- .c0 {
27
- -webkit-align-items: stretch;
28
- -webkit-box-align: stretch;
29
- -ms-flex-align: stretch;
30
- align-items: stretch;
31
- display: -webkit-box;
32
- display: -webkit-flex;
33
- display: -ms-flexbox;
34
- display: flex;
35
- -webkit-flex-direction: column;
36
- -ms-flex-direction: column;
37
- flex-direction: column;
38
- gap: 4px;
39
- }
40
-
41
- .c4 {
42
- -webkit-align-items: center;
43
- -webkit-box-align: center;
44
- -ms-flex-align: center;
45
- align-items: center;
46
- display: -webkit-box;
47
- display: -webkit-flex;
48
- display: -ms-flexbox;
49
- display: flex;
50
- -webkit-flex-direction: row;
51
- -ms-flex-direction: row;
52
- flex-direction: row;
53
- }
54
-
55
- .c5 {
56
- position: relative;
57
- outline: none;
58
- }
59
-
60
- .c5 > svg {
61
- height: 12px;
62
- width: 12px;
63
- }
64
-
65
- .c5 > svg > g,
66
- .c5 > svg path {
67
- fill: #ffffff;
68
- }
69
-
70
- .c5[aria-disabled='true'] {
71
- pointer-events: none;
72
- }
73
-
74
- .c5:after {
75
- -webkit-transition-property: all;
76
- transition-property: all;
77
- -webkit-transition-duration: 0.2s;
78
- transition-duration: 0.2s;
79
- border-radius: 8px;
80
- content: '';
81
- position: absolute;
82
- top: -4px;
83
- bottom: -4px;
84
- left: -4px;
85
- right: -4px;
86
- border: 2px solid transparent;
87
- }
88
-
89
- .c5:focus-visible {
90
- outline: none;
91
- }
92
-
93
- .c5:focus-visible:after {
94
- border-radius: 8px;
95
- content: '';
96
- position: absolute;
97
- top: -5px;
98
- bottom: -5px;
99
- left: -5px;
100
- right: -5px;
101
- border: 2px solid #4945ff;
102
- }
103
-
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
- .c2 {
117
- display: -webkit-box;
118
- display: -webkit-flex;
119
- display: -ms-flexbox;
120
- display: flex;
121
- -webkit-align-items: center;
122
- -webkit-box-align: center;
123
- -ms-flex-align: center;
124
- align-items: center;
125
- }
126
-
127
- .c7 {
128
- border-radius: 50%;
129
- width: 20px;
130
- height: 20px;
131
- margin-right: 10px;
132
- background-color: #000000;
133
- border: 1px solid rgba(0,0,0,0.1);
134
- }
135
-
136
- .c6 {
137
- display: -webkit-box;
138
- display: -webkit-flex;
139
- display: -ms-flexbox;
140
- display: flex;
141
- -webkit-box-pack: justify;
142
- -webkit-justify-content: space-between;
143
- -ms-flex-pack: justify;
144
- justify-content: space-between;
145
- -webkit-align-items: center;
146
- -webkit-box-align: center;
147
- -ms-flex-align: center;
148
- align-items: center;
149
- }
150
-
151
- .c6 svg {
152
- width: 8px;
153
- height: 8px;
154
- }
155
-
156
- .c6 svg > path {
157
- fill: #8e8ea9;
158
- justify-self: flex-end;
159
- }
160
-
161
- <div>
162
- <div
163
- class=""
164
- >
165
- <div
166
- class="c0"
167
- >
168
- <label
169
- class="c1 c2"
170
- for="color"
171
- >
172
- color-picker
173
- </label>
174
- <button
175
- aria-controls="color-picker-value"
176
- aria-disabled="false"
177
- aria-expanded="false"
178
- aria-haspopup="dialog"
179
- aria-label="Color picker toggle"
180
- class="c3 c4 c5 c6"
181
- type="button"
182
- >
183
- <div
184
- class="c4"
185
- >
186
- <div
187
- class="c7"
188
- color="#000000"
189
- />
190
- <span
191
- class="c8"
192
- style="text-transform: uppercase;"
193
- >
194
- #000000
195
- </span>
196
- </div>
197
- <svg
198
- aria-hidden="true"
199
- fill="none"
200
- height="1rem"
201
- viewBox="0 0 14 8"
202
- width="1rem"
203
- xmlns="http://www.w3.org/2000/svg"
204
- >
205
- <path
206
- clip-rule="evenodd"
207
- d="M14 .889a.86.86 0 0 1-.26.625L7.615 7.736A.834.834 0 0 1 7 8a.834.834 0 0 1-.615-.264L.26 1.514A.861.861 0 0 1 0 .889c0-.24.087-.45.26-.625A.834.834 0 0 1 .875 0h12.25c.237 0 .442.088.615.264a.86.86 0 0 1 .26.625Z"
208
- fill="#32324D"
209
- fill-rule="evenodd"
210
- />
211
- </svg>
212
- </button>
213
- </div>
214
- </div>
215
- <div
216
- class="c9"
217
- >
218
- <p
219
- aria-live="polite"
220
- aria-relevant="all"
221
- id="live-region-log"
222
- role="log"
223
- />
224
- <p
225
- aria-live="polite"
226
- aria-relevant="all"
227
- id="live-region-status"
228
- role="status"
229
- />
230
- <p
231
- aria-live="assertive"
232
- aria-relevant="all"
233
- id="live-region-alert"
234
- role="alert"
235
- />
236
- </div>
237
- </div>
238
- `;
@@ -1,63 +0,0 @@
1
- import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import { lightTheme, ThemeProvider } from '@strapi/design-system';
4
- import { IntlProvider } from 'react-intl';
5
- import ColorPickerInput from '../ColorPicker/ColorPickerInput';
6
-
7
- const mockAttribute = {
8
- customField: 'plugin::color-picker.color',
9
- pluginOptions: { i18n: { localized: true } },
10
- type: 'string',
11
- };
12
-
13
- const App = (
14
- <IntlProvider locale="en" messages={{}} textComponent="span">
15
- <ThemeProvider theme={lightTheme}>
16
- <ColorPickerInput
17
- name="color"
18
- value=""
19
- onChange={jest.fn()}
20
- attribute={mockAttribute}
21
- intlLabel={{ id: 'color-picker', defaultMessage: 'color-picker' }}
22
- />
23
- </ThemeProvider>
24
- </IntlProvider>
25
- );
26
-
27
- describe('<ColorPickerInput />', () => {
28
- /**
29
- * We do this because –
30
- * https://github.com/facebook/jest/issues/12670
31
- */
32
- beforeAll(() => {
33
- jest.setTimeout(30000);
34
- });
35
-
36
- /**
37
- * Reset timeout to what is expected
38
- */
39
- afterAll(() => {
40
- jest.setTimeout(5000);
41
- });
42
-
43
- it('renders and matches the snapshot', () => {
44
- const { container } = render(App);
45
-
46
- expect(container).toMatchSnapshot();
47
- });
48
-
49
- it('toggles the popover', () => {
50
- render(App);
51
- const colorPickerToggle = screen.getByRole('button', { name: 'Color picker toggle' });
52
- fireEvent.click(colorPickerToggle);
53
-
54
- const popover = screen.getByRole('dialog');
55
- const saturation = screen.getByRole('slider', { name: 'Color' });
56
- const hue = screen.getByRole('slider', { name: 'Hue' });
57
- const input = screen.getByRole('textbox', { name: 'Color picker input' });
58
- expect(popover).toBeVisible();
59
- expect(saturation).toBeVisible();
60
- expect(hue).toBeVisible();
61
- expect(input).toBeVisible();
62
- });
63
- });
@@ -1,87 +0,0 @@
1
- import { prefixPluginTranslations } from '@strapi/helper-plugin';
2
- import pluginId from './pluginId';
3
- import ColorPickerIcon from './components/ColorPicker/ColorPickerIcon';
4
- import getTrad from './utils/getTrad';
5
-
6
- export default {
7
- register(app) {
8
- app.customFields.register({
9
- name: 'color',
10
- pluginId: 'color-picker',
11
- type: 'string',
12
- icon: ColorPickerIcon,
13
- intlLabel: {
14
- id: getTrad('color-picker.label'),
15
- defaultMessage: 'Color',
16
- },
17
- intlDescription: {
18
- id: getTrad('color-picker.description'),
19
- defaultMessage: 'Select any color',
20
- },
21
- components: {
22
- Input: async () =>
23
- import(
24
- /* webpackChunkName: "color-picker-input-component" */ './components/ColorPicker/ColorPickerInput'
25
- ),
26
- },
27
- options: {
28
- advanced: [
29
- {
30
- intlLabel: {
31
- id: getTrad('color-picker.options.advanced.regex'),
32
- defaultMessage: 'RegExp pattern',
33
- },
34
- name: 'regex',
35
- type: 'text',
36
- defaultValue: '^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$',
37
- description: {
38
- id: getTrad('color-picker.options.advanced.regex.description'),
39
- defaultMessage: 'The text of the regular expression',
40
- },
41
- },
42
- {
43
- sectionTitle: {
44
- id: 'global.settings',
45
- defaultMessage: 'Settings',
46
- },
47
- items: [
48
- {
49
- name: 'required',
50
- type: 'checkbox',
51
- intlLabel: {
52
- id: getTrad('color-picker.options.advanced.requiredField'),
53
- defaultMessage: 'Required field',
54
- },
55
- description: {
56
- id: getTrad('color-picker.options.advanced.requiredField.description'),
57
- defaultMessage: "You won't be able to create an entry if this field is empty",
58
- },
59
- },
60
- ],
61
- },
62
- ],
63
- },
64
- });
65
- },
66
- async registerTrads({ locales }) {
67
- const importedTrads = await Promise.all(
68
- locales.map((locale) => {
69
- return import(`./translations/${locale}.json`)
70
- .then(({ default: data }) => {
71
- return {
72
- data: prefixPluginTranslations(data, pluginId),
73
- locale,
74
- };
75
- })
76
- .catch(() => {
77
- return {
78
- data: {},
79
- locale,
80
- };
81
- });
82
- })
83
- );
84
-
85
- return Promise.resolve(importedTrads);
86
- },
87
- };
@@ -1,5 +0,0 @@
1
- const pluginPkg = require('../../package.json');
2
-
3
- const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
4
-
5
- module.exports = pluginId;
@@ -1,5 +0,0 @@
1
- import pluginId from '../pluginId';
2
-
3
- const getTrad = (id) => `${pluginId}.${id}`;
4
-
5
- export default getTrad;
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
- };
package/strapi-admin.js DELETED
@@ -1,3 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = require('./admin/src').default;
package/strapi-server.js DELETED
@@ -1,3 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = require('./server');