@strapi/plugin-color-picker 0.0.0-experimental.62ebf57bb35846666febb5ee2078fe02fe990f57 → 0.0.0-experimental.6340da17068c3bed7fb006e7bcc554c71129e282
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/dist/admin/components/ColorPickerIcon.js +31 -0
- package/dist/admin/components/ColorPickerIcon.js.map +1 -0
- package/dist/admin/components/ColorPickerIcon.mjs +29 -0
- package/dist/admin/components/ColorPickerIcon.mjs.map +1 -0
- package/dist/admin/components/ColorPickerInput.js +206 -0
- package/dist/admin/components/ColorPickerInput.js.map +1 -0
- package/dist/admin/components/ColorPickerInput.mjs +184 -0
- package/dist/admin/components/ColorPickerInput.mjs.map +1 -0
- package/dist/admin/index.js +109 -8
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +104 -8
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/pluginId.js +6 -0
- package/dist/admin/pluginId.js.map +1 -0
- package/dist/admin/pluginId.mjs +4 -0
- package/dist/admin/pluginId.mjs.map +1 -0
- package/dist/admin/src/components/ColorPickerInput.d.ts +3 -28
- package/dist/admin/src/components/tests/ColorPickerInput.test.d.ts +1 -0
- package/dist/admin/src/utils/prefixPluginTranslations.d.ts +3 -0
- package/dist/admin/translations/cs.json.js +20 -0
- package/dist/admin/translations/cs.json.js.map +1 -0
- package/dist/admin/translations/cs.json.mjs +18 -0
- package/dist/admin/translations/cs.json.mjs.map +1 -0
- package/dist/admin/translations/en.json.js +20 -0
- package/dist/admin/translations/en.json.js.map +1 -0
- package/dist/admin/translations/en.json.mjs +18 -0
- package/dist/admin/translations/en.json.mjs.map +1 -0
- package/dist/admin/translations/es.json.js +20 -0
- package/dist/admin/translations/es.json.js.map +1 -0
- package/dist/admin/translations/es.json.mjs +18 -0
- package/dist/admin/translations/es.json.mjs.map +1 -0
- package/dist/admin/translations/ru.json.js +20 -0
- package/dist/admin/translations/ru.json.js.map +1 -0
- package/dist/admin/translations/ru.json.mjs +18 -0
- package/dist/admin/translations/ru.json.mjs.map +1 -0
- package/dist/admin/translations/sk.json.js +20 -0
- package/dist/admin/translations/sk.json.js.map +1 -0
- package/dist/admin/translations/sk.json.mjs +18 -0
- package/dist/admin/translations/sk.json.mjs.map +1 -0
- package/dist/admin/translations/sv.json.js +17 -0
- package/dist/admin/translations/sv.json.js.map +1 -0
- package/dist/admin/translations/sv.json.mjs +15 -0
- package/dist/admin/translations/sv.json.mjs.map +1 -0
- package/dist/admin/translations/tr.json.js +17 -0
- package/dist/admin/translations/tr.json.js.map +1 -0
- package/dist/admin/translations/tr.json.mjs +15 -0
- package/dist/admin/translations/tr.json.mjs.map +1 -0
- package/dist/admin/translations/uk.json.js +20 -0
- package/dist/admin/translations/uk.json.js.map +1 -0
- package/dist/admin/translations/uk.json.mjs +18 -0
- package/dist/admin/translations/uk.json.mjs.map +1 -0
- package/dist/admin/translations/zh.json.js +17 -0
- package/dist/admin/translations/zh.json.js.map +1 -0
- package/dist/admin/translations/zh.json.mjs +15 -0
- package/dist/admin/translations/zh.json.mjs.map +1 -0
- package/dist/admin/utils/getTrad.js +8 -0
- package/dist/admin/utils/getTrad.js.map +1 -0
- package/dist/admin/utils/getTrad.mjs +6 -0
- package/dist/admin/utils/getTrad.mjs.map +1 -0
- package/dist/admin/utils/prefixPluginTranslations.js +11 -0
- package/dist/admin/utils/prefixPluginTranslations.js.map +1 -0
- package/dist/admin/utils/prefixPluginTranslations.mjs +9 -0
- package/dist/admin/utils/prefixPluginTranslations.mjs.map +1 -0
- package/dist/server/index.js +7 -10
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +6 -12
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/register.js +12 -0
- package/dist/server/register.js.map +1 -0
- package/dist/server/register.mjs +10 -0
- package/dist/server/register.mjs.map +1 -0
- package/dist/server/src/register.d.ts.map +1 -1
- package/package.json +32 -24
- package/dist/_chunks/ColorPickerInput-0lOoTrf0.js +0 -206
- package/dist/_chunks/ColorPickerInput-0lOoTrf0.js.map +0 -1
- package/dist/_chunks/ColorPickerInput-fKB6YXW8.mjs +0 -185
- package/dist/_chunks/ColorPickerInput-fKB6YXW8.mjs.map +0 -1
- package/dist/_chunks/cs-4GdZY0p6.js +0 -16
- package/dist/_chunks/cs-4GdZY0p6.js.map +0 -1
- package/dist/_chunks/cs-A2xRj-2-.mjs +0 -16
- package/dist/_chunks/cs-A2xRj-2-.mjs.map +0 -1
- package/dist/_chunks/en-L6ZZWDJv.mjs +0 -19
- package/dist/_chunks/en-L6ZZWDJv.mjs.map +0 -1
- package/dist/_chunks/en-WeRHjVEB.js +0 -19
- package/dist/_chunks/en-WeRHjVEB.js.map +0 -1
- package/dist/_chunks/index-OJYEuoCq.js +0 -117
- package/dist/_chunks/index-OJYEuoCq.js.map +0 -1
- package/dist/_chunks/index-uOrtnJpz.mjs +0 -116
- package/dist/_chunks/index-uOrtnJpz.mjs.map +0 -1
- package/dist/_chunks/ru-LLXYEOwl.mjs +0 -19
- package/dist/_chunks/ru-LLXYEOwl.mjs.map +0 -1
- package/dist/_chunks/ru-UXN_ByI9.js +0 -19
- package/dist/_chunks/ru-UXN_ByI9.js.map +0 -1
- package/dist/_chunks/sv-3-Yk9bKb.js +0 -16
- package/dist/_chunks/sv-3-Yk9bKb.js.map +0 -1
- package/dist/_chunks/sv-QqRPNQLw.mjs +0 -16
- package/dist/_chunks/sv-QqRPNQLw.mjs.map +0 -1
- package/dist/_chunks/tr-AbD-f8F0.js +0 -16
- package/dist/_chunks/tr-AbD-f8F0.js.map +0 -1
- package/dist/_chunks/tr-qYGSw8gH.mjs +0 -16
- package/dist/_chunks/tr-qYGSw8gH.mjs.map +0 -1
- package/dist/_chunks/zh-c23gv_oM.js +0 -16
- package/dist/_chunks/zh-c23gv_oM.js.map +0 -1
- package/dist/_chunks/zh-fPTOIT6s.mjs +0 -16
- package/dist/_chunks/zh-fPTOIT6s.mjs.map +0 -1
- package/dist/admin/src/hooks/useComposeRefs.d.ts +0 -29
- package/strapi-server.js +0 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var designSystem = require('@strapi/design-system');
|
|
5
|
+
var icons = require('@strapi/icons');
|
|
6
|
+
var styledComponents = require('styled-components');
|
|
7
|
+
|
|
8
|
+
const IconBox = styledComponents.styled(designSystem.Flex)`
|
|
9
|
+
/* Hard code color values */
|
|
10
|
+
/* to stay consistent between themes */
|
|
11
|
+
background-color: #f0f0ff; /* primary100 */
|
|
12
|
+
border: 1px solid #d9d8ff; /* primary200 */
|
|
13
|
+
|
|
14
|
+
svg > path {
|
|
15
|
+
fill: #4945ff; /* primary600 */
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
const ColorPickerIcon = ()=>{
|
|
19
|
+
return /*#__PURE__*/ jsxRuntime.jsx(IconBox, {
|
|
20
|
+
justifyContent: "center",
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
width: 7,
|
|
23
|
+
height: 6,
|
|
24
|
+
hasRadius: true,
|
|
25
|
+
"aria-hidden": true,
|
|
26
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(icons.PaintBrush, {})
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.ColorPickerIcon = ColorPickerIcon;
|
|
31
|
+
//# sourceMappingURL=ColorPickerIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorPickerIcon.js","sources":["../../../admin/src/components/ColorPickerIcon.tsx"],"sourcesContent":["import { Flex } from '@strapi/design-system';\nimport { PaintBrush } from '@strapi/icons';\nimport { styled } from 'styled-components';\n\nconst IconBox = styled(Flex)`\n /* Hard code color values */\n /* to stay consistent between themes */\n background-color: #f0f0ff; /* primary100 */\n border: 1px solid #d9d8ff; /* primary200 */\n\n svg > path {\n fill: #4945ff; /* primary600 */\n }\n`;\n\nexport const ColorPickerIcon = () => {\n return (\n <IconBox justifyContent=\"center\" alignItems=\"center\" width={7} height={6} hasRadius aria-hidden>\n <PaintBrush />\n </IconBox>\n );\n};\n"],"names":["IconBox","styled","Flex","ColorPickerIcon","_jsx","justifyContent","alignItems","width","height","hasRadius","aria-hidden","PaintBrush"],"mappings":";;;;;;;AAIA,MAAMA,OAAAA,GAAUC,uBAAAA,CAAOC,iBAAAA,CAAK;;;;;;;;;AAS5B,CAAC;MAEYC,eAAAA,GAAkB,IAAA;AAC7B,IAAA,qBACEC,cAAA,CAACJ,OAAAA,EAAAA;QAAQK,cAAAA,EAAe,QAAA;QAASC,UAAAA,EAAW,QAAA;QAASC,KAAAA,EAAO,CAAA;QAAGC,MAAAA,EAAQ,CAAA;QAAGC,SAAS,EAAA,IAAA;QAACC,aAAW,EAAA,IAAA;AAC7F,QAAA,QAAA,gBAAAN,cAAA,CAACO,gBAAAA,EAAAA,EAAAA;;AAGP;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Flex } from '@strapi/design-system';
|
|
3
|
+
import { PaintBrush } from '@strapi/icons';
|
|
4
|
+
import { styled } from 'styled-components';
|
|
5
|
+
|
|
6
|
+
const IconBox = styled(Flex)`
|
|
7
|
+
/* Hard code color values */
|
|
8
|
+
/* to stay consistent between themes */
|
|
9
|
+
background-color: #f0f0ff; /* primary100 */
|
|
10
|
+
border: 1px solid #d9d8ff; /* primary200 */
|
|
11
|
+
|
|
12
|
+
svg > path {
|
|
13
|
+
fill: #4945ff; /* primary600 */
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
const ColorPickerIcon = ()=>{
|
|
17
|
+
return /*#__PURE__*/ jsx(IconBox, {
|
|
18
|
+
justifyContent: "center",
|
|
19
|
+
alignItems: "center",
|
|
20
|
+
width: 7,
|
|
21
|
+
height: 6,
|
|
22
|
+
hasRadius: true,
|
|
23
|
+
"aria-hidden": true,
|
|
24
|
+
children: /*#__PURE__*/ jsx(PaintBrush, {})
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { ColorPickerIcon };
|
|
29
|
+
//# sourceMappingURL=ColorPickerIcon.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorPickerIcon.mjs","sources":["../../../admin/src/components/ColorPickerIcon.tsx"],"sourcesContent":["import { Flex } from '@strapi/design-system';\nimport { PaintBrush } from '@strapi/icons';\nimport { styled } from 'styled-components';\n\nconst IconBox = styled(Flex)`\n /* Hard code color values */\n /* to stay consistent between themes */\n background-color: #f0f0ff; /* primary100 */\n border: 1px solid #d9d8ff; /* primary200 */\n\n svg > path {\n fill: #4945ff; /* primary600 */\n }\n`;\n\nexport const ColorPickerIcon = () => {\n return (\n <IconBox justifyContent=\"center\" alignItems=\"center\" width={7} height={6} hasRadius aria-hidden>\n <PaintBrush />\n </IconBox>\n );\n};\n"],"names":["IconBox","styled","Flex","ColorPickerIcon","_jsx","justifyContent","alignItems","width","height","hasRadius","aria-hidden","PaintBrush"],"mappings":";;;;;AAIA,MAAMA,OAAAA,GAAUC,MAAAA,CAAOC,IAAAA,CAAK;;;;;;;;;AAS5B,CAAC;MAEYC,eAAAA,GAAkB,IAAA;AAC7B,IAAA,qBACEC,GAAA,CAACJ,OAAAA,EAAAA;QAAQK,cAAAA,EAAe,QAAA;QAASC,UAAAA,EAAW,QAAA;QAASC,KAAAA,EAAO,CAAA;QAAGC,MAAAA,EAAQ,CAAA;QAAGC,SAAS,EAAA,IAAA;QAACC,aAAW,EAAA,IAAA;AAC7F,QAAA,QAAA,gBAAAN,GAAA,CAACO,UAAAA,EAAAA,EAAAA;;AAGP;;;;"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var designSystem = require('@strapi/design-system');
|
|
6
|
+
var icons = require('@strapi/icons');
|
|
7
|
+
var admin = require('@strapi/strapi/admin');
|
|
8
|
+
var reactColorful = require('react-colorful');
|
|
9
|
+
var reactIntl = require('react-intl');
|
|
10
|
+
var styledComponents = require('styled-components');
|
|
11
|
+
var getTrad = require('../utils/getTrad.js');
|
|
12
|
+
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
|
+
|
|
33
|
+
const ColorPreview = styledComponents.styled.div`
|
|
34
|
+
border-radius: 50%;
|
|
35
|
+
width: 20px;
|
|
36
|
+
height: 20px;
|
|
37
|
+
margin-right: 10px;
|
|
38
|
+
background-color: ${(props)=>props.color};
|
|
39
|
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
40
|
+
`;
|
|
41
|
+
const ColorPicker = styledComponents.styled(reactColorful.HexColorPicker)`
|
|
42
|
+
&& {
|
|
43
|
+
width: 100%;
|
|
44
|
+
aspect-ratio: 1.5;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.react-colorful__pointer {
|
|
48
|
+
width: ${({ theme })=>theme.spaces[3]};
|
|
49
|
+
height: ${({ theme })=>theme.spaces[3]};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.react-colorful__saturation {
|
|
53
|
+
border-radius: ${({ theme })=>theme.spaces[1]};
|
|
54
|
+
border-bottom: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.react-colorful__hue {
|
|
58
|
+
border-radius: 10px;
|
|
59
|
+
height: ${({ theme })=>theme.spaces[3]};
|
|
60
|
+
margin-top: ${({ theme })=>theme.spaces[2]};
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
const ColorPickerToggle = styledComponents.styled(designSystem.Button)`
|
|
64
|
+
& > span {
|
|
65
|
+
display: flex;
|
|
66
|
+
justify-content: space-between;
|
|
67
|
+
align-items: center;
|
|
68
|
+
width: 100%;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
svg {
|
|
72
|
+
width: ${({ theme })=>theme.spaces[2]};
|
|
73
|
+
height: ${({ theme })=>theme.spaces[2]};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
svg > path {
|
|
77
|
+
fill: ${({ theme })=>theme.colors.neutral500};
|
|
78
|
+
justify-self: flex-end;
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
const ColorPickerPopover = styledComponents.styled(designSystem.Popover.Content)`
|
|
82
|
+
padding: ${({ theme })=>theme.spaces[2]};
|
|
83
|
+
min-height: 270px;
|
|
84
|
+
`;
|
|
85
|
+
const ColorPickerInput = /*#__PURE__*/ React__namespace.forwardRef(({ hint, disabled, labelAction, label, name, required, ...props }, forwardedRef)=>{
|
|
86
|
+
const [showColorPicker, setShowColorPicker] = React__namespace.useState(false);
|
|
87
|
+
const colorPickerButtonRef = React__namespace.useRef(null);
|
|
88
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
89
|
+
const field = admin.useField(name);
|
|
90
|
+
/**
|
|
91
|
+
* The color that will show in the field. We can't presume to show black or something
|
|
92
|
+
* if no value is currently set (as `null` really corresponds to no color, not
|
|
93
|
+
* black), so default to empty string if nothing else is available. */ const color = field.value ?? props.placeholder ?? '';
|
|
94
|
+
const composedRefs = designSystem.useComposedRefs(forwardedRef, colorPickerButtonRef);
|
|
95
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Root, {
|
|
96
|
+
name: name,
|
|
97
|
+
id: name,
|
|
98
|
+
error: field.error,
|
|
99
|
+
hint: hint,
|
|
100
|
+
required: required,
|
|
101
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
|
102
|
+
direction: "column",
|
|
103
|
+
alignItems: "stretch",
|
|
104
|
+
gap: 1,
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
|
|
107
|
+
action: labelAction,
|
|
108
|
+
children: label
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Popover.Root, {
|
|
111
|
+
onOpenChange: setShowColorPicker,
|
|
112
|
+
children: [
|
|
113
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Popover.Trigger, {
|
|
114
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(ColorPickerToggle, {
|
|
115
|
+
ref: composedRefs,
|
|
116
|
+
"aria-label": formatMessage({
|
|
117
|
+
id: getTrad.getTrad('color-picker.toggle.aria-label'),
|
|
118
|
+
defaultMessage: 'Color picker toggle'
|
|
119
|
+
}),
|
|
120
|
+
"aria-controls": "color-picker-value",
|
|
121
|
+
"aria-haspopup": "dialog",
|
|
122
|
+
"aria-expanded": showColorPicker,
|
|
123
|
+
"aria-disabled": disabled,
|
|
124
|
+
disabled: disabled,
|
|
125
|
+
variant: "tertiary",
|
|
126
|
+
size: "L",
|
|
127
|
+
children: [
|
|
128
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
|
129
|
+
children: [
|
|
130
|
+
/*#__PURE__*/ jsxRuntime.jsx(ColorPreview, {
|
|
131
|
+
color: color
|
|
132
|
+
}),
|
|
133
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
|
134
|
+
style: {
|
|
135
|
+
textTransform: 'uppercase'
|
|
136
|
+
},
|
|
137
|
+
textColor: field.value ? undefined : 'neutral500',
|
|
138
|
+
variant: "omega",
|
|
139
|
+
children: color
|
|
140
|
+
})
|
|
141
|
+
]
|
|
142
|
+
}),
|
|
143
|
+
/*#__PURE__*/ jsxRuntime.jsx(icons.CaretDown, {
|
|
144
|
+
"aria-hidden": true
|
|
145
|
+
})
|
|
146
|
+
]
|
|
147
|
+
})
|
|
148
|
+
}),
|
|
149
|
+
/*#__PURE__*/ jsxRuntime.jsxs(ColorPickerPopover, {
|
|
150
|
+
sideOffset: 4,
|
|
151
|
+
children: [
|
|
152
|
+
/*#__PURE__*/ jsxRuntime.jsx(ColorPicker, {
|
|
153
|
+
color: color,
|
|
154
|
+
onChange: (hexValue)=>field.onChange(name, hexValue)
|
|
155
|
+
}),
|
|
156
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
|
157
|
+
paddingTop: 3,
|
|
158
|
+
paddingLeft: 4,
|
|
159
|
+
justifyContent: "flex-end",
|
|
160
|
+
children: [
|
|
161
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
|
162
|
+
paddingRight: 2,
|
|
163
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
|
164
|
+
variant: "omega",
|
|
165
|
+
tag: "label",
|
|
166
|
+
textColor: "neutral600",
|
|
167
|
+
children: formatMessage({
|
|
168
|
+
id: getTrad.getTrad('color-picker.input.format'),
|
|
169
|
+
defaultMessage: 'HEX'
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Root, {
|
|
174
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Input, {
|
|
175
|
+
"aria-label": formatMessage({
|
|
176
|
+
id: getTrad.getTrad('color-picker.input.aria-label'),
|
|
177
|
+
defaultMessage: 'Color picker input'
|
|
178
|
+
}),
|
|
179
|
+
style: {
|
|
180
|
+
textTransform: 'uppercase'
|
|
181
|
+
},
|
|
182
|
+
name: name,
|
|
183
|
+
// No default value. If nothing is selected, the input will be empty.
|
|
184
|
+
defaultValue: field.value ?? '',
|
|
185
|
+
// Here we default to #000000 as the placeholder, because, absent a
|
|
186
|
+
// user defined placeholder, we want to indicate the desired format.
|
|
187
|
+
placeholder: "#000000",
|
|
188
|
+
onChange: field.onChange,
|
|
189
|
+
...props
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
]
|
|
193
|
+
})
|
|
194
|
+
]
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
}),
|
|
198
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Hint, {}),
|
|
199
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Error, {})
|
|
200
|
+
]
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
exports.ColorPickerInput = ColorPickerInput;
|
|
206
|
+
//# sourceMappingURL=ColorPickerInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorPickerInput.js","sources":["../../../admin/src/components/ColorPickerInput.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Button,\n Box,\n Field,\n Flex,\n Popover,\n Typography,\n useComposedRefs,\n} from '@strapi/design-system';\nimport { CaretDown } from '@strapi/icons';\nimport { type InputProps, useField } from '@strapi/strapi/admin';\nimport { HexColorPicker } from 'react-colorful';\nimport { useIntl } from 'react-intl';\nimport { styled } from 'styled-components';\n\nimport { getTrad } from '../utils/getTrad';\n\nconst ColorPreview = styled.div`\n border-radius: 50%;\n width: 20px;\n height: 20px;\n margin-right: 10px;\n background-color: ${(props) => props.color};\n border: 1px solid rgba(0, 0, 0, 0.1);\n`;\n\nconst ColorPicker = styled(HexColorPicker)`\n && {\n width: 100%;\n aspect-ratio: 1.5;\n }\n\n .react-colorful__pointer {\n width: ${({ theme }) => theme.spaces[3]};\n height: ${({ theme }) => theme.spaces[3]};\n }\n\n .react-colorful__saturation {\n border-radius: ${({ theme }) => theme.spaces[1]};\n border-bottom: none;\n }\n\n .react-colorful__hue {\n border-radius: 10px;\n height: ${({ theme }) => theme.spaces[3]};\n margin-top: ${({ theme }) => theme.spaces[2]};\n }\n`;\n\nconst ColorPickerToggle = styled(Button)`\n & > span {\n display: flex;\n justify-content: space-between;\n align-items: center;\n width: 100%;\n }\n\n svg {\n width: ${({ theme }) => theme.spaces[2]};\n height: ${({ theme }) => theme.spaces[2]};\n }\n\n svg > path {\n fill: ${({ theme }) => theme.colors.neutral500};\n justify-self: flex-end;\n }\n`;\n\nconst ColorPickerPopover = styled(Popover.Content)`\n padding: ${({ theme }) => theme.spaces[2]};\n min-height: 270px;\n`;\n\ntype ColorPickerInputProps = InputProps & {\n labelAction?: React.ReactNode;\n};\n\nexport const ColorPickerInput = React.forwardRef<HTMLButtonElement, ColorPickerInputProps>(\n ({ hint, disabled, labelAction, label, name, required, ...props }, forwardedRef) => {\n const [showColorPicker, setShowColorPicker] = React.useState(false);\n const colorPickerButtonRef = React.useRef<HTMLButtonElement>(null!);\n const { formatMessage } = useIntl();\n const field = useField(name);\n\n /**\n * The color that will show in the field. We can't presume to show black or something\n * if no value is currently set (as `null` really corresponds to no color, not\n * black), so default to empty string if nothing else is available. */\n const color = field.value ?? props.placeholder ?? '';\n\n const composedRefs = useComposedRefs(forwardedRef, colorPickerButtonRef);\n\n return (\n <Field.Root name={name} id={name} error={field.error} hint={hint} required={required}>\n <Flex direction=\"column\" alignItems=\"stretch\" gap={1}>\n <Field.Label action={labelAction}>{label}</Field.Label>\n <Popover.Root onOpenChange={setShowColorPicker}>\n <Popover.Trigger>\n <ColorPickerToggle\n ref={composedRefs}\n aria-label={formatMessage({\n id: getTrad('color-picker.toggle.aria-label'),\n defaultMessage: 'Color picker toggle',\n })}\n aria-controls=\"color-picker-value\"\n aria-haspopup=\"dialog\"\n aria-expanded={showColorPicker}\n aria-disabled={disabled}\n disabled={disabled}\n variant=\"tertiary\"\n size=\"L\"\n >\n <Flex>\n <ColorPreview color={color} />\n <Typography\n style={{ textTransform: 'uppercase' }}\n textColor={field.value ? undefined : 'neutral500'}\n variant=\"omega\"\n >\n {color}\n </Typography>\n </Flex>\n <CaretDown aria-hidden />\n </ColorPickerToggle>\n </Popover.Trigger>\n <ColorPickerPopover sideOffset={4}>\n <ColorPicker color={color} onChange={(hexValue) => field.onChange(name, hexValue)} />\n <Flex paddingTop={3} paddingLeft={4} justifyContent=\"flex-end\">\n <Box paddingRight={2}>\n <Typography variant=\"omega\" tag=\"label\" textColor=\"neutral600\">\n {formatMessage({\n id: getTrad('color-picker.input.format'),\n defaultMessage: 'HEX',\n })}\n </Typography>\n </Box>\n <Field.Root>\n <Field.Input\n aria-label={formatMessage({\n id: getTrad('color-picker.input.aria-label'),\n defaultMessage: 'Color picker input',\n })}\n style={{ textTransform: 'uppercase' }}\n name={name}\n // No default value. If nothing is selected, the input will be empty.\n defaultValue={field.value ?? ''}\n // Here we default to #000000 as the placeholder, because, absent a\n // user defined placeholder, we want to indicate the desired format.\n placeholder=\"#000000\"\n onChange={field.onChange}\n {...props}\n />\n </Field.Root>\n </Flex>\n </ColorPickerPopover>\n </Popover.Root>\n <Field.Hint />\n <Field.Error />\n </Flex>\n </Field.Root>\n );\n }\n);\n"],"names":["ColorPreview","styled","div","props","color","ColorPicker","HexColorPicker","theme","spaces","ColorPickerToggle","Button","colors","neutral500","ColorPickerPopover","Popover","Content","ColorPickerInput","React","forwardRef","hint","disabled","labelAction","label","name","required","forwardedRef","showColorPicker","setShowColorPicker","useState","colorPickerButtonRef","useRef","formatMessage","useIntl","field","useField","value","placeholder","composedRefs","useComposedRefs","_jsx","Field","Root","id","error","_jsxs","Flex","direction","alignItems","gap","Label","action","onOpenChange","Trigger","ref","aria-label","getTrad","defaultMessage","aria-controls","aria-haspopup","aria-expanded","aria-disabled","variant","size","Typography","style","textTransform","textColor","undefined","CaretDown","aria-hidden","sideOffset","onChange","hexValue","paddingT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AAGC,cAAAA,EAAe,UAAA;;sDAClDpC,cAAA,CAACqC,gBAAAA,EAAAA;4CAAIC,YAAAA,EAAc,CAAA;AACjB,4CAAA,QAAA,gBAAAtC,cAAA,CAACwB,uBAAAA,EAAAA;gDAAWF,OAAAA,EAAQ,OAAA;gDAAQiB,GAAAA,EAAI,OAAA;gDAAQZ,SAAAA,EAAU,YAAA;0DAC/CnC,aAAAA,CAAc;AACbW,oDAAAA,EAAAA,EAAIa,eAAAA,CAAQ,2BAAA,CAAA;oDACZC,cAAAA,EAAgB;AAClB,iDAAA;;;AAGJ,sDAAAjB,cAAA,CAACC,mBAAMC,IAAI,EAAA;oEACTF,cAAA,CAACC,mBAAMuC,KAAK,EAAA;AACVzB,gDAAAA,YAAAA,EAAYvB,aAAAA,CAAc;AACxBW,oDAAAA,EAAAA,EAAIa,eAAAA,CAAQ,+BAAA,CAAA;oDACZC,cAAAA,EAAgB;AAClB,iDAAA,CAAA;gDACAQ,KAAAA,EAAO;oDAAEC,aAAAA,EAAe;AAAY,iDAAA;gDACpC1C,IAAAA,EAAMA,IAAAA;;gDAENyD,YAAAA,EAAc/C,KAAAA,CAAME,KAAK,IAAI,EAAA;;;gDAG7BC,WAAAA,EAAY,SAAA;AACZmC,gDAAAA,QAAAA,EAAUtC,MAAMsC,QAAQ;AACvB,gDAAA,GAAGpE;;;;;;;;;AAMd,8BAAAoC,cAAA,CAACC,mBAAMyC,IAAI,EAAA,EAAA,CAAA;AACX,8BAAA1C,cAAA,CAACC,mBAAM0C,KAAK,EAAA,EAAA;;;;AAIpB,CAAA;;;;"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useComposedRefs, Field, Flex, Popover, Typography, Box, Button } from '@strapi/design-system';
|
|
4
|
+
import { CaretDown } from '@strapi/icons';
|
|
5
|
+
import { useField } from '@strapi/strapi/admin';
|
|
6
|
+
import { HexColorPicker } from 'react-colorful';
|
|
7
|
+
import { useIntl } from 'react-intl';
|
|
8
|
+
import { styled } from 'styled-components';
|
|
9
|
+
import { getTrad } from '../utils/getTrad.mjs';
|
|
10
|
+
|
|
11
|
+
const ColorPreview = styled.div`
|
|
12
|
+
border-radius: 50%;
|
|
13
|
+
width: 20px;
|
|
14
|
+
height: 20px;
|
|
15
|
+
margin-right: 10px;
|
|
16
|
+
background-color: ${(props)=>props.color};
|
|
17
|
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
18
|
+
`;
|
|
19
|
+
const ColorPicker = styled(HexColorPicker)`
|
|
20
|
+
&& {
|
|
21
|
+
width: 100%;
|
|
22
|
+
aspect-ratio: 1.5;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.react-colorful__pointer {
|
|
26
|
+
width: ${({ theme })=>theme.spaces[3]};
|
|
27
|
+
height: ${({ theme })=>theme.spaces[3]};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.react-colorful__saturation {
|
|
31
|
+
border-radius: ${({ theme })=>theme.spaces[1]};
|
|
32
|
+
border-bottom: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.react-colorful__hue {
|
|
36
|
+
border-radius: 10px;
|
|
37
|
+
height: ${({ theme })=>theme.spaces[3]};
|
|
38
|
+
margin-top: ${({ theme })=>theme.spaces[2]};
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
const ColorPickerToggle = styled(Button)`
|
|
42
|
+
& > span {
|
|
43
|
+
display: flex;
|
|
44
|
+
justify-content: space-between;
|
|
45
|
+
align-items: center;
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
svg {
|
|
50
|
+
width: ${({ theme })=>theme.spaces[2]};
|
|
51
|
+
height: ${({ theme })=>theme.spaces[2]};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
svg > path {
|
|
55
|
+
fill: ${({ theme })=>theme.colors.neutral500};
|
|
56
|
+
justify-self: flex-end;
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
const ColorPickerPopover = styled(Popover.Content)`
|
|
60
|
+
padding: ${({ theme })=>theme.spaces[2]};
|
|
61
|
+
min-height: 270px;
|
|
62
|
+
`;
|
|
63
|
+
const ColorPickerInput = /*#__PURE__*/ React.forwardRef(({ hint, disabled, labelAction, label, name, required, ...props }, forwardedRef)=>{
|
|
64
|
+
const [showColorPicker, setShowColorPicker] = React.useState(false);
|
|
65
|
+
const colorPickerButtonRef = React.useRef(null);
|
|
66
|
+
const { formatMessage } = useIntl();
|
|
67
|
+
const field = useField(name);
|
|
68
|
+
/**
|
|
69
|
+
* The color that will show in the field. We can't presume to show black or something
|
|
70
|
+
* if no value is currently set (as `null` really corresponds to no color, not
|
|
71
|
+
* black), so default to empty string if nothing else is available. */ const color = field.value ?? props.placeholder ?? '';
|
|
72
|
+
const composedRefs = useComposedRefs(forwardedRef, colorPickerButtonRef);
|
|
73
|
+
return /*#__PURE__*/ jsx(Field.Root, {
|
|
74
|
+
name: name,
|
|
75
|
+
id: name,
|
|
76
|
+
error: field.error,
|
|
77
|
+
hint: hint,
|
|
78
|
+
required: required,
|
|
79
|
+
children: /*#__PURE__*/ jsxs(Flex, {
|
|
80
|
+
direction: "column",
|
|
81
|
+
alignItems: "stretch",
|
|
82
|
+
gap: 1,
|
|
83
|
+
children: [
|
|
84
|
+
/*#__PURE__*/ jsx(Field.Label, {
|
|
85
|
+
action: labelAction,
|
|
86
|
+
children: label
|
|
87
|
+
}),
|
|
88
|
+
/*#__PURE__*/ jsxs(Popover.Root, {
|
|
89
|
+
onOpenChange: setShowColorPicker,
|
|
90
|
+
children: [
|
|
91
|
+
/*#__PURE__*/ jsx(Popover.Trigger, {
|
|
92
|
+
children: /*#__PURE__*/ jsxs(ColorPickerToggle, {
|
|
93
|
+
ref: composedRefs,
|
|
94
|
+
"aria-label": formatMessage({
|
|
95
|
+
id: getTrad('color-picker.toggle.aria-label'),
|
|
96
|
+
defaultMessage: 'Color picker toggle'
|
|
97
|
+
}),
|
|
98
|
+
"aria-controls": "color-picker-value",
|
|
99
|
+
"aria-haspopup": "dialog",
|
|
100
|
+
"aria-expanded": showColorPicker,
|
|
101
|
+
"aria-disabled": disabled,
|
|
102
|
+
disabled: disabled,
|
|
103
|
+
variant: "tertiary",
|
|
104
|
+
size: "L",
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ jsxs(Flex, {
|
|
107
|
+
children: [
|
|
108
|
+
/*#__PURE__*/ jsx(ColorPreview, {
|
|
109
|
+
color: color
|
|
110
|
+
}),
|
|
111
|
+
/*#__PURE__*/ jsx(Typography, {
|
|
112
|
+
style: {
|
|
113
|
+
textTransform: 'uppercase'
|
|
114
|
+
},
|
|
115
|
+
textColor: field.value ? undefined : 'neutral500',
|
|
116
|
+
variant: "omega",
|
|
117
|
+
children: color
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
}),
|
|
121
|
+
/*#__PURE__*/ jsx(CaretDown, {
|
|
122
|
+
"aria-hidden": true
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
}),
|
|
127
|
+
/*#__PURE__*/ jsxs(ColorPickerPopover, {
|
|
128
|
+
sideOffset: 4,
|
|
129
|
+
children: [
|
|
130
|
+
/*#__PURE__*/ jsx(ColorPicker, {
|
|
131
|
+
color: color,
|
|
132
|
+
onChange: (hexValue)=>field.onChange(name, hexValue)
|
|
133
|
+
}),
|
|
134
|
+
/*#__PURE__*/ jsxs(Flex, {
|
|
135
|
+
paddingTop: 3,
|
|
136
|
+
paddingLeft: 4,
|
|
137
|
+
justifyContent: "flex-end",
|
|
138
|
+
children: [
|
|
139
|
+
/*#__PURE__*/ jsx(Box, {
|
|
140
|
+
paddingRight: 2,
|
|
141
|
+
children: /*#__PURE__*/ jsx(Typography, {
|
|
142
|
+
variant: "omega",
|
|
143
|
+
tag: "label",
|
|
144
|
+
textColor: "neutral600",
|
|
145
|
+
children: formatMessage({
|
|
146
|
+
id: getTrad('color-picker.input.format'),
|
|
147
|
+
defaultMessage: 'HEX'
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
}),
|
|
151
|
+
/*#__PURE__*/ jsx(Field.Root, {
|
|
152
|
+
children: /*#__PURE__*/ jsx(Field.Input, {
|
|
153
|
+
"aria-label": formatMessage({
|
|
154
|
+
id: getTrad('color-picker.input.aria-label'),
|
|
155
|
+
defaultMessage: 'Color picker input'
|
|
156
|
+
}),
|
|
157
|
+
style: {
|
|
158
|
+
textTransform: 'uppercase'
|
|
159
|
+
},
|
|
160
|
+
name: name,
|
|
161
|
+
// No default value. If nothing is selected, the input will be empty.
|
|
162
|
+
defaultValue: field.value ?? '',
|
|
163
|
+
// Here we default to #000000 as the placeholder, because, absent a
|
|
164
|
+
// user defined placeholder, we want to indicate the desired format.
|
|
165
|
+
placeholder: "#000000",
|
|
166
|
+
onChange: field.onChange,
|
|
167
|
+
...props
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
]
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
})
|
|
174
|
+
]
|
|
175
|
+
}),
|
|
176
|
+
/*#__PURE__*/ jsx(Field.Hint, {}),
|
|
177
|
+
/*#__PURE__*/ jsx(Field.Error, {})
|
|
178
|
+
]
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
export { ColorPickerInput };
|
|
184
|
+
//# sourceMappingURL=ColorPickerInput.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorPickerInput.mjs","sources":["../../../admin/src/components/ColorPickerInput.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Button,\n Box,\n Field,\n Flex,\n Popover,\n Typography,\n useComposedRefs,\n} from '@strapi/design-system';\nimport { CaretDown } from '@strapi/icons';\nimport { type InputProps, useField } from '@strapi/strapi/admin';\nimport { HexColorPicker } from 'react-colorful';\nimport { useIntl } from 'react-intl';\nimport { styled } from 'styled-components';\n\nimport { getTrad } from '../utils/getTrad';\n\nconst ColorPreview = styled.div`\n border-radius: 50%;\n width: 20px;\n height: 20px;\n margin-right: 10px;\n background-color: ${(props) => props.color};\n border: 1px solid rgba(0, 0, 0, 0.1);\n`;\n\nconst ColorPicker = styled(HexColorPicker)`\n && {\n width: 100%;\n aspect-ratio: 1.5;\n }\n\n .react-colorful__pointer {\n width: ${({ theme }) => theme.spaces[3]};\n height: ${({ theme }) => theme.spaces[3]};\n }\n\n .react-colorful__saturation {\n border-radius: ${({ theme }) => theme.spaces[1]};\n border-bottom: none;\n }\n\n .react-colorful__hue {\n border-radius: 10px;\n height: ${({ theme }) => theme.spaces[3]};\n margin-top: ${({ theme }) => theme.spaces[2]};\n }\n`;\n\nconst ColorPickerToggle = styled(Button)`\n & > span {\n display: flex;\n justify-content: space-between;\n align-items: center;\n width: 100%;\n }\n\n svg {\n width: ${({ theme }) => theme.spaces[2]};\n height: ${({ theme }) => theme.spaces[2]};\n }\n\n svg > path {\n fill: ${({ theme }) => theme.colors.neutral500};\n justify-self: flex-end;\n }\n`;\n\nconst ColorPickerPopover = styled(Popover.Content)`\n padding: ${({ theme }) => theme.spaces[2]};\n min-height: 270px;\n`;\n\ntype ColorPickerInputProps = InputProps & {\n labelAction?: React.ReactNode;\n};\n\nexport const ColorPickerInput = React.forwardRef<HTMLButtonElement, ColorPickerInputProps>(\n ({ hint, disabled, labelAction, label, name, required, ...props }, forwardedRef) => {\n const [showColorPicker, setShowColorPicker] = React.useState(false);\n const colorPickerButtonRef = React.useRef<HTMLButtonElement>(null!);\n const { formatMessage } = useIntl();\n const field = useField(name);\n\n /**\n * The color that will show in the field. We can't presume to show black or something\n * if no value is currently set (as `null` really corresponds to no color, not\n * black), so default to empty string if nothing else is available. */\n const color = field.value ?? props.placeholder ?? '';\n\n const composedRefs = useComposedRefs(forwardedRef, colorPickerButtonRef);\n\n return (\n <Field.Root name={name} id={name} error={field.error} hint={hint} required={required}>\n <Flex direction=\"column\" alignItems=\"stretch\" gap={1}>\n <Field.Label action={labelAction}>{label}</Field.Label>\n <Popover.Root onOpenChange={setShowColorPicker}>\n <Popover.Trigger>\n <ColorPickerToggle\n ref={composedRefs}\n aria-label={formatMessage({\n id: getTrad('color-picker.toggle.aria-label'),\n defaultMessage: 'Color picker toggle',\n })}\n aria-controls=\"color-picker-value\"\n aria-haspopup=\"dialog\"\n aria-expanded={showColorPicker}\n aria-disabled={disabled}\n disabled={disabled}\n variant=\"tertiary\"\n size=\"L\"\n >\n <Flex>\n <ColorPreview color={color} />\n <Typography\n style={{ textTransform: 'uppercase' }}\n textColor={field.value ? undefined : 'neutral500'}\n variant=\"omega\"\n >\n {color}\n </Typography>\n </Flex>\n <CaretDown aria-hidden />\n </ColorPickerToggle>\n </Popover.Trigger>\n <ColorPickerPopover sideOffset={4}>\n <ColorPicker color={color} onChange={(hexValue) => field.onChange(name, hexValue)} />\n <Flex paddingTop={3} paddingLeft={4} justifyContent=\"flex-end\">\n <Box paddingRight={2}>\n <Typography variant=\"omega\" tag=\"label\" textColor=\"neutral600\">\n {formatMessage({\n id: getTrad('color-picker.input.format'),\n defaultMessage: 'HEX',\n })}\n </Typography>\n </Box>\n <Field.Root>\n <Field.Input\n aria-label={formatMessage({\n id: getTrad('color-picker.input.aria-label'),\n defaultMessage: 'Color picker input',\n })}\n style={{ textTransform: 'uppercase' }}\n name={name}\n // No default value. If nothing is selected, the input will be empty.\n defaultValue={field.value ?? ''}\n // Here we default to #000000 as the placeholder, because, absent a\n // user defined placeholder, we want to indicate the desired format.\n placeholder=\"#000000\"\n onChange={field.onChange}\n {...props}\n />\n </Field.Root>\n </Flex>\n </ColorPickerPopover>\n </Popover.Root>\n <Field.Hint />\n <Field.Error />\n </Flex>\n </Field.Root>\n );\n }\n);\n"],"names":["ColorPreview","styled","div","props","color","ColorPicker","HexColorPicker","theme","spaces","ColorPickerToggle","Button","colors","neutral500","ColorPickerPopover","Popover","Content","ColorPickerInput","React","forwardRef","hint","disabled","labelAction","label","name","required","forwardedRef","showColorPicker","setShowColorPicker","useState","colorPickerButtonRef","useRef","formatMessage","useIntl","field","useField","value","placeholder","composedRefs","useComposedRefs","_jsx","Field","Root","id","error","_jsxs","Flex","direction","alignItems","gap","Label","action","onOpenChange","Trigger","ref","aria-label","getTrad","defaultMessage","aria-controls","aria-haspopup","aria-expanded","aria-disabled","variant","size","Typography","style","textTransform","textColor","undefined","CaretDown","aria-hidden","sideOffset","onChange","hexValue","paddingTop","paddingLeft","justifyContent","Box","paddingRight","tag","Input","defaultValue","Hint","Error"],"mappings":";;;;;;;;;;AAmBA,MAAMA,YAAAA,GAAeC,MAAAA,CAAOC,GAAG;;;;;AAKX,oBAAA,EAAE,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,KAAK,CAAC;;AAE7C,CAAC;AAED,MAAMC,WAAAA,GAAcJ,MAAAA,CAAOK,cAAAA,CAAe;;;;;;;WAO/B,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;YAChC,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;;;;mBAI1B,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;;;;;;YAMxC,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;gBAC7B,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;;AAEjD,CAAC;AAED,MAAMC,iBAAAA,GAAoBR,MAAAA,CAAOS,MAAAA,CAAO;;;;;;;;;WAS7B,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAAA,CAAMC,MAAM,CAAC,CAAA,CAAE,CAAC;YAChC,EAAE,CAAC,EAAED,KAAK,E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package/dist/admin/index.js
CHANGED
|
@@ -1,9 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require(
|
|
4
|
-
require(
|
|
5
|
-
require(
|
|
6
|
-
require(
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ColorPickerIcon = require('./components/ColorPickerIcon.js');
|
|
4
|
+
var pluginId = require('./pluginId.js');
|
|
5
|
+
var getTrad = require('./utils/getTrad.js');
|
|
6
|
+
var prefixPluginTranslations = require('./utils/prefixPluginTranslations.js');
|
|
7
|
+
|
|
8
|
+
function _interopNamespaceDefaultOnly (e) { return Object.freeze({ __proto__: null, default: e }); }
|
|
9
|
+
|
|
10
|
+
function __variableDynamicImportRuntime1__(path) {
|
|
11
|
+
switch (path) {
|
|
12
|
+
case './translations/cs.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/cs.json.js')); });
|
|
13
|
+
case './translations/en.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/en.json.js')); });
|
|
14
|
+
case './translations/es.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/es.json.js')); });
|
|
15
|
+
case './translations/ru.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/ru.json.js')); });
|
|
16
|
+
case './translations/sk.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/sk.json.js')); });
|
|
17
|
+
case './translations/sv.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/sv.json.js')); });
|
|
18
|
+
case './translations/tr.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/tr.json.js')); });
|
|
19
|
+
case './translations/uk.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/uk.json.js')); });
|
|
20
|
+
case './translations/zh.json': return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('./translations/zh.json.js')); });
|
|
21
|
+
default: return new Promise(function(resolve, reject) {
|
|
22
|
+
(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(
|
|
23
|
+
reject.bind(null, new Error("Unknown variable dynamic import: " + path))
|
|
24
|
+
);
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// eslint-disable-next-line import/no-default-export
|
|
29
|
+
var index = {
|
|
30
|
+
/**
|
|
31
|
+
* TODO: we need to have the type for StrapiApp done from `@strapi/admin` package.
|
|
32
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
register (app) {
|
|
34
|
+
app.customFields.register({
|
|
35
|
+
name: 'color',
|
|
36
|
+
pluginId: 'color-picker',
|
|
37
|
+
type: 'string',
|
|
38
|
+
icon: ColorPickerIcon.ColorPickerIcon,
|
|
39
|
+
intlLabel: {
|
|
40
|
+
id: getTrad.getTrad('color-picker.label'),
|
|
41
|
+
defaultMessage: 'Color'
|
|
42
|
+
},
|
|
43
|
+
intlDescription: {
|
|
44
|
+
id: getTrad.getTrad('color-picker.description'),
|
|
45
|
+
defaultMessage: 'Select any color'
|
|
46
|
+
},
|
|
47
|
+
components: {
|
|
48
|
+
Input: async ()=>Promise.resolve().then(function () { return require('./components/ColorPickerInput.js'); }).then((module)=>({
|
|
49
|
+
default: module.ColorPickerInput
|
|
50
|
+
}))
|
|
51
|
+
},
|
|
52
|
+
options: {
|
|
53
|
+
advanced: [
|
|
54
|
+
{
|
|
55
|
+
intlLabel: {
|
|
56
|
+
id: getTrad.getTrad('color-picker.options.advanced.regex'),
|
|
57
|
+
defaultMessage: 'RegExp pattern'
|
|
58
|
+
},
|
|
59
|
+
name: 'regex',
|
|
60
|
+
type: 'text',
|
|
61
|
+
defaultValue: '^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$',
|
|
62
|
+
description: {
|
|
63
|
+
id: getTrad.getTrad('color-picker.options.advanced.regex.description'),
|
|
64
|
+
defaultMessage: 'The text of the regular expression'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
sectionTitle: {
|
|
69
|
+
id: 'global.settings',
|
|
70
|
+
defaultMessage: 'Settings'
|
|
71
|
+
},
|
|
72
|
+
items: [
|
|
73
|
+
{
|
|
74
|
+
name: 'required',
|
|
75
|
+
type: 'checkbox',
|
|
76
|
+
intlLabel: {
|
|
77
|
+
id: getTrad.getTrad('color-picker.options.advanced.requiredField'),
|
|
78
|
+
defaultMessage: 'Required field'
|
|
79
|
+
},
|
|
80
|
+
description: {
|
|
81
|
+
id: getTrad.getTrad('color-picker.options.advanced.requiredField.description'),
|
|
82
|
+
defaultMessage: "You won't be able to create an entry if this field is empty"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
async registerTrads ({ locales }) {
|
|
92
|
+
const importedTrads = await Promise.all(locales.map((locale)=>{
|
|
93
|
+
return __variableDynamicImportRuntime1__(`./translations/${locale}.json`).then(({ default: data })=>{
|
|
94
|
+
return {
|
|
95
|
+
data: prefixPluginTranslations.prefixPluginTranslations(data, pluginId.pluginId),
|
|
96
|
+
locale
|
|
97
|
+
};
|
|
98
|
+
}).catch(()=>{
|
|
99
|
+
return {
|
|
100
|
+
data: {},
|
|
101
|
+
locale
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}));
|
|
105
|
+
return Promise.resolve(importedTrads);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
module.exports = index;
|
|
9
110
|
//# sourceMappingURL=index.js.map
|