@frontify/guideline-blocks-settings 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +15 -0
- package/README.md +24 -5
- package/package.json +46 -10
- package/postcss.config.js +8 -0
- package/setupTests.ts +13 -0
- package/src/components/Attachments/AttachmentItem.tsx +257 -0
- package/src/components/Attachments/Attachments.spec.ct.tsx +151 -0
- package/src/components/Attachments/Attachments.tsx +221 -0
- package/src/components/Attachments/index.ts +4 -0
- package/src/components/Attachments/types.ts +30 -0
- package/src/components/BlockInjectButton/BlockInjectButton.spec.ct.tsx +48 -0
- package/src/components/BlockInjectButton/BlockInjectButton.tsx +212 -0
- package/src/components/BlockInjectButton/index.ts +4 -0
- package/src/components/BlockInjectButton/types.ts +18 -0
- package/src/components/BlockItemWrapper/BlockItemWrapper.spec.ct.tsx +146 -0
- package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +76 -0
- package/src/components/BlockItemWrapper/Toolbar.tsx +128 -0
- package/src/components/BlockItemWrapper/constants.ts +4 -0
- package/src/components/BlockItemWrapper/index.ts +5 -0
- package/src/components/BlockItemWrapper/types.ts +46 -0
- package/src/components/DownloadButton/DownloadButton.spec.ct.tsx +20 -0
- package/src/components/DownloadButton/DownloadButton.tsx +36 -0
- package/src/components/DownloadButton/index.ts +3 -0
- package/src/components/DownloadButton/types.ts +5 -0
- package/src/components/RichTextEditor/RichTextEditor.spec.ct.tsx +204 -0
- package/src/components/RichTextEditor/RichTextEditor.tsx +62 -0
- package/src/components/RichTextEditor/SerializedText.tsx +25 -0
- package/src/components/RichTextEditor/constants.ts +3 -0
- package/src/components/RichTextEditor/index.ts +6 -0
- package/src/components/RichTextEditor/pluginPresets/defaultPluginsWithLinkChooser.tsx +53 -0
- package/src/components/RichTextEditor/pluginPresets/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/ButtonMarkupElementNode.tsx +74 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/index.ts +11 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonButton.tsx +20 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonToolbarButton.tsx +56 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/CustomFloatingButton.tsx +19 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/EditButtonModal/EditModal.tsx +42 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButton.tsx +37 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonEditButton.tsx +22 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonUrlInput.tsx +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/InsertButtonModal.tsx +81 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/types.ts +13 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/useInsertModal.ts +143 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/UnlinkButton.tsx +31 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.ts +46 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/index.ts +12 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEdit.ts +113 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEnter.ts +21 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEscape.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonInsert.ts +71 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useVirtualFloatingButton.ts +22 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/createButtonPlugin.ts +116 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/index.ts +7 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/index.ts +8 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/insertButton.ts +17 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/submitFloatingButton.ts +40 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/unwrapButton.ts +68 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButton.ts +198 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButtonText.ts +40 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/wrapButton.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/types.ts +13 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/createButtonNode.ts +28 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getButtonStyle.ts +14 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getUrl.ts +18 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/index.ts +8 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/styles.ts +77 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButton.ts +23 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonEdit.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.ts +45 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/withButton.ts +106 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/CustomFloatingLink.tsx +26 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.tsx +43 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/useFloatingLinkEdit.ts +113 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/FloatingLink.tsx +45 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertLinkModal.tsx +5 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertModal.tsx +105 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/types.ts +16 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useFloatingLinkInsert.ts +73 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useInsertModal.ts +136 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkButton.tsx +38 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/LinkMarkupElementNode.tsx +36 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/index.ts +11 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/id.ts +3 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/index.ts +48 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/types.ts +12 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/getUrl.ts +30 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.spec.ts +35 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.ts +3 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.spec.ts +75 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.ts +21 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom1Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom2Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom3Plugin.tsx +62 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading1Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading2Plugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading3Plugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading4Plugin.tsx +59 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/helpers.tsx +44 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/imageCaptionPlugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/imageTitlePlugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/index.ts +15 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/paragraphPlugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/quotePlugin.tsx +62 -0
- package/src/components/RichTextEditor/plugins/index.ts +6 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLink.tsx +80 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLinks.tsx +97 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.spec.ct.tsx +138 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.tsx +80 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLink.tsx +83 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLinks.tsx +68 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/SectionLink.tsx +37 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/styles.ts +179 -0
- package/src/components/RichTextEditor/serializer/index.ts +3 -0
- package/src/components/RichTextEditor/serializer/nodes/button.ts +25 -0
- package/src/components/RichTextEditor/serializer/nodes/checkItemNode.ts +29 -0
- package/src/components/RichTextEditor/serializer/nodes/default.ts +52 -0
- package/src/components/RichTextEditor/serializer/nodes/link.ts +25 -0
- package/src/components/RichTextEditor/serializer/nodes/mentionHtmlNode.ts +17 -0
- package/src/components/RichTextEditor/serializer/serializeNodesToHtmlRecursive.ts +134 -0
- package/src/components/RichTextEditor/serializer/serializeToHtml.ts +49 -0
- package/src/components/RichTextEditor/serializer/utlis/reactCssPropsToCss.ts +21 -0
- package/src/components/RichTextEditor/serializer/utlis/serializeLeafToHtml.ts +32 -0
- package/src/components/RichTextEditor/types.ts +23 -0
- package/src/components/index.ts +7 -0
- package/src/helpers/addHttps.spec.ts +42 -0
- package/src/helpers/addHttps.ts +15 -0
- package/src/helpers/convertToRichTextValue.spec.ts +32 -0
- package/src/helpers/convertToRichTextValue.ts +6 -0
- package/src/helpers/customCoordinatesGetterFactory.spec.ts +69 -0
- package/src/helpers/customCoordinatesGetterFactory.ts +39 -0
- package/src/helpers/hasRichTextValue.spec.ts +63 -0
- package/src/helpers/hasRichTextValue.ts +29 -0
- package/src/helpers/index.ts +8 -0
- package/src/helpers/isDownloadable.spec.ts +47 -0
- package/src/helpers/isDownloadable.ts +7 -0
- package/src/helpers/mapColorPalettes.spec.ts +146 -0
- package/src/helpers/mapColorPalettes.ts +22 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAttachments.spec.ts +79 -0
- package/src/hooks/useAttachments.ts +46 -0
- package/src/hooks/useDndSensors.spec.ts +40 -0
- package/src/hooks/useDndSensors.ts +23 -0
- package/src/index.ts +8 -0
- package/src/settings/background.spec.ts +173 -0
- package/src/settings/background.ts +49 -0
- package/src/settings/border.spec.ts +76 -0
- package/src/settings/border.ts +90 -0
- package/src/settings/borderRadius.spec.ts +30 -0
- package/src/settings/borderRadius.ts +73 -0
- package/src/settings/borderRadiusExtended.spec.ts +52 -0
- package/src/settings/borderRadiusExtended.ts +84 -0
- package/src/settings/defaultValues.ts +21 -0
- package/src/settings/gutter.spec.ts +60 -0
- package/src/settings/gutter.ts +75 -0
- package/src/settings/index.ts +14 -0
- package/src/settings/margin.spec.ts +42 -0
- package/src/settings/margin.ts +72 -0
- package/src/settings/marginExtended.spec.ts +45 -0
- package/src/settings/marginExtended.ts +91 -0
- package/src/settings/padding.spec.ts +42 -0
- package/src/settings/padding.ts +73 -0
- package/src/settings/paddingExtended.spec.ts +45 -0
- package/src/settings/paddingExtended.ts +91 -0
- package/src/settings/security.spec.ts +87 -0
- package/src/settings/security.ts +61 -0
- package/src/settings/securityDownloadable.spec.ts +46 -0
- package/src/settings/securityDownloadable.ts +33 -0
- package/src/settings/securityGlobalControl.ts +42 -0
- package/src/settings/types.ts +128 -0
- package/src/utilities/color/getReadableColor.spec.ts +32 -0
- package/src/utilities/color/getReadableColor.ts +34 -0
- package/src/utilities/color/index.ts +10 -0
- package/src/utilities/color/isDark.spec.ts +33 -0
- package/src/utilities/color/isDark.ts +29 -0
- package/src/utilities/color/setAlpha.spec.ts +28 -0
- package/src/utilities/color/setAlpha.ts +14 -0
- package/src/utilities/color/toColorObject.spec.ts +19 -0
- package/src/utilities/color/toColorObject.ts +16 -0
- package/src/utilities/color/toHex8String.spec.ts +17 -0
- package/src/utilities/color/toHex8String.ts +14 -0
- package/src/utilities/color/toHexString.spec.ts +17 -0
- package/src/utilities/color/toHexString.ts +10 -0
- package/src/utilities/color/toRgbaString.spec.ts +12 -0
- package/src/utilities/color/toRgbaString.ts +14 -0
- package/src/utilities/color/toShortRgba.spec.ts +16 -0
- package/src/utilities/color/toShortRgba.ts +35 -0
- package/src/utilities/index.ts +5 -0
- package/src/utilities/moveItemInArray.spec.ts +17 -0
- package/src/utilities/moveItemInArray.ts +21 -0
- package/src/utilities/react/getBackgroundColorStyles.spec.ts +18 -0
- package/src/utilities/react/getBackgroundColorStyles.ts +11 -0
- package/src/utilities/react/getBorderStyles.spec.ts +39 -0
- package/src/utilities/react/getBorderStyles.ts +21 -0
- package/src/utilities/react/getRadiusStyles.spec.ts +25 -0
- package/src/utilities/react/getRadiusStyles.ts +8 -0
- package/src/utilities/react/index.ts +6 -0
- package/src/utilities/react/joinClassNames.spec.ts +18 -0
- package/src/utilities/react/joinClassNames.ts +10 -0
- package/tailwind.config.js +27 -0
- package/tsconfig.json +3 -1
- package/vite.config.ts +11 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -147
- package/dist/index.es.js +0 -9
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
|
|
4
|
+
import { customCoordinatesGetterFactory } from '../helpers/customCoordinatesGetterFactory';
|
|
5
|
+
|
|
6
|
+
const keyboardCodes = {
|
|
7
|
+
start: ['Space', 'Enter'],
|
|
8
|
+
cancel: [],
|
|
9
|
+
end: ['Space', 'Enter', 'Escape'],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const useDndSensors = (columnGap = 0, rowGap = 0) => {
|
|
13
|
+
const customCoordinatesGetter = customCoordinatesGetterFactory(columnGap, rowGap);
|
|
14
|
+
const sensors = useSensors(
|
|
15
|
+
useSensor(PointerSensor),
|
|
16
|
+
useSensor(KeyboardSensor, {
|
|
17
|
+
coordinateGetter: customCoordinatesGetter,
|
|
18
|
+
keyboardCodes,
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return sensors;
|
|
23
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
2
|
|
|
3
|
+
import 'tailwindcss/tailwind.css';
|
|
4
|
+
|
|
3
5
|
import type { FC } from 'react';
|
|
4
6
|
import type { AppBridgeBlock } from '@frontify/app-bridge';
|
|
5
7
|
import type {
|
|
@@ -126,3 +128,9 @@ export const defineSettings = <
|
|
|
126
128
|
>(
|
|
127
129
|
settingsStructure: T
|
|
128
130
|
): T => settingsStructure;
|
|
131
|
+
|
|
132
|
+
export * from './components';
|
|
133
|
+
export * from './helpers';
|
|
134
|
+
export * from './hooks';
|
|
135
|
+
export * from './settings';
|
|
136
|
+
export * from './utilities';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { getBackgroundSettings } from './background';
|
|
5
|
+
|
|
6
|
+
describe('getBackgroundSettings', () => {
|
|
7
|
+
it('should return background settings without arguments', () => {
|
|
8
|
+
expect(getBackgroundSettings()).toEqual({
|
|
9
|
+
id: 'hasBackground',
|
|
10
|
+
label: 'Background',
|
|
11
|
+
type: 'switch',
|
|
12
|
+
defaultValue: false,
|
|
13
|
+
on: [
|
|
14
|
+
{
|
|
15
|
+
id: 'backgroundColor',
|
|
16
|
+
defaultValue: {
|
|
17
|
+
red: 241,
|
|
18
|
+
green: 241,
|
|
19
|
+
blue: 241,
|
|
20
|
+
alpha: 1,
|
|
21
|
+
},
|
|
22
|
+
type: 'colorInput',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return background settings with id', () => {
|
|
29
|
+
expect(getBackgroundSettings({ id: 'Test' })).toEqual({
|
|
30
|
+
id: 'hasBackgroundTest',
|
|
31
|
+
label: 'Background',
|
|
32
|
+
type: 'switch',
|
|
33
|
+
defaultValue: false,
|
|
34
|
+
on: [
|
|
35
|
+
{
|
|
36
|
+
id: 'backgroundColorTest',
|
|
37
|
+
defaultValue: {
|
|
38
|
+
red: 241,
|
|
39
|
+
green: 241,
|
|
40
|
+
blue: 241,
|
|
41
|
+
alpha: 1,
|
|
42
|
+
},
|
|
43
|
+
type: 'colorInput',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return background settings with default value', () => {
|
|
50
|
+
expect(getBackgroundSettings({ defaultValue: true })).toEqual({
|
|
51
|
+
id: 'hasBackground',
|
|
52
|
+
label: 'Background',
|
|
53
|
+
type: 'switch',
|
|
54
|
+
defaultValue: true,
|
|
55
|
+
on: [
|
|
56
|
+
{
|
|
57
|
+
id: 'backgroundColor',
|
|
58
|
+
defaultValue: {
|
|
59
|
+
red: 241,
|
|
60
|
+
green: 241,
|
|
61
|
+
blue: 241,
|
|
62
|
+
alpha: 1,
|
|
63
|
+
},
|
|
64
|
+
type: 'colorInput',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should return background settings with default color', () => {
|
|
71
|
+
expect(getBackgroundSettings({ defaultColor: { red: 0, green: 0, blue: 0, alpha: 1 } })).toEqual({
|
|
72
|
+
id: 'hasBackground',
|
|
73
|
+
label: 'Background',
|
|
74
|
+
type: 'switch',
|
|
75
|
+
defaultValue: false,
|
|
76
|
+
on: [
|
|
77
|
+
{
|
|
78
|
+
id: 'backgroundColor',
|
|
79
|
+
defaultValue: {
|
|
80
|
+
red: 0,
|
|
81
|
+
green: 0,
|
|
82
|
+
blue: 0,
|
|
83
|
+
alpha: 1,
|
|
84
|
+
},
|
|
85
|
+
type: 'colorInput',
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should return background settings with id, default value and default color', () => {
|
|
92
|
+
expect(
|
|
93
|
+
getBackgroundSettings({
|
|
94
|
+
id: 'Test',
|
|
95
|
+
defaultValue: true,
|
|
96
|
+
defaultColor: { red: 0, green: 0, blue: 0, alpha: 1 },
|
|
97
|
+
})
|
|
98
|
+
).toEqual({
|
|
99
|
+
id: 'hasBackgroundTest',
|
|
100
|
+
label: 'Background',
|
|
101
|
+
type: 'switch',
|
|
102
|
+
defaultValue: true,
|
|
103
|
+
on: [
|
|
104
|
+
{
|
|
105
|
+
id: 'backgroundColorTest',
|
|
106
|
+
defaultValue: {
|
|
107
|
+
red: 0,
|
|
108
|
+
green: 0,
|
|
109
|
+
blue: 0,
|
|
110
|
+
alpha: 1,
|
|
111
|
+
},
|
|
112
|
+
type: 'colorInput',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should return background settings with switch label', () => {
|
|
119
|
+
expect(getBackgroundSettings({ switchLabel: 'Test' })).toEqual({
|
|
120
|
+
id: 'hasBackground',
|
|
121
|
+
label: 'Background',
|
|
122
|
+
type: 'switch',
|
|
123
|
+
switchLabel: 'Test',
|
|
124
|
+
defaultValue: false,
|
|
125
|
+
on: [
|
|
126
|
+
{
|
|
127
|
+
id: 'backgroundColor',
|
|
128
|
+
defaultValue: {
|
|
129
|
+
red: 241,
|
|
130
|
+
green: 241,
|
|
131
|
+
blue: 241,
|
|
132
|
+
alpha: 1,
|
|
133
|
+
},
|
|
134
|
+
type: 'colorInput',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it('should not return default color if hasDefaultColor is false', () => {
|
|
140
|
+
expect(getBackgroundSettings({ preventDefaultColor: true })).toEqual({
|
|
141
|
+
id: 'hasBackground',
|
|
142
|
+
label: 'Background',
|
|
143
|
+
type: 'switch',
|
|
144
|
+
defaultValue: false,
|
|
145
|
+
on: [
|
|
146
|
+
{
|
|
147
|
+
id: 'backgroundColor',
|
|
148
|
+
type: 'colorInput',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
it('should return default color if hasDefaultColor is true', () => {
|
|
154
|
+
expect(getBackgroundSettings({ preventDefaultColor: false })).toEqual({
|
|
155
|
+
id: 'hasBackground',
|
|
156
|
+
label: 'Background',
|
|
157
|
+
type: 'switch',
|
|
158
|
+
defaultValue: false,
|
|
159
|
+
on: [
|
|
160
|
+
{
|
|
161
|
+
id: 'backgroundColor',
|
|
162
|
+
defaultValue: {
|
|
163
|
+
red: 241,
|
|
164
|
+
green: 241,
|
|
165
|
+
blue: 241,
|
|
166
|
+
alpha: 1,
|
|
167
|
+
},
|
|
168
|
+
type: 'colorInput',
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { Color } from '@frontify/fondue';
|
|
4
|
+
import { BACKGROUND_COLOR_DEFAULT_VALUE } from './defaultValues';
|
|
5
|
+
import { SettingBlock } from '../';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns background settings: background switch, background color
|
|
9
|
+
*
|
|
10
|
+
* @param options Options for the settings
|
|
11
|
+
* @param options.id Custom suffix for the setting ids
|
|
12
|
+
* @param options.defaultValue Default value for the background switch
|
|
13
|
+
* @param options.defaultColor Default value for the background color
|
|
14
|
+
* @param options.preventDefaultColor Whether the background color should be empty by default
|
|
15
|
+
* @param options.switchLabel Label for the background switch
|
|
16
|
+
* @returns {SettingBlock} Returns background settings
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type BackgroundSettingsType = {
|
|
20
|
+
id?: string;
|
|
21
|
+
defaultValue?: boolean;
|
|
22
|
+
defaultColor?: Color;
|
|
23
|
+
preventDefaultColor?: boolean;
|
|
24
|
+
switchLabel?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getBackgroundSettings = (options?: BackgroundSettingsType): SettingBlock => {
|
|
28
|
+
const hasId = options?.id ? `hasBackground${options.id}` : 'hasBackground';
|
|
29
|
+
const colorId = options?.id ? `backgroundColor${options.id}` : 'backgroundColor';
|
|
30
|
+
const defaultColor = !!options?.preventDefaultColor
|
|
31
|
+
? undefined
|
|
32
|
+
: options?.defaultColor || BACKGROUND_COLOR_DEFAULT_VALUE;
|
|
33
|
+
const switchLabel = options?.switchLabel ? options.switchLabel : undefined;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
id: hasId,
|
|
37
|
+
label: 'Background',
|
|
38
|
+
type: 'switch',
|
|
39
|
+
switchLabel,
|
|
40
|
+
defaultValue: !!options?.defaultValue,
|
|
41
|
+
on: [
|
|
42
|
+
{
|
|
43
|
+
id: colorId,
|
|
44
|
+
defaultValue: defaultColor,
|
|
45
|
+
type: 'colorInput',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { getBorderSettings } from './border';
|
|
5
|
+
import { MultiInputBlock, MultiInputLayout } from '@frontify/sidebar-settings';
|
|
6
|
+
import { BorderStyle } from '../settings';
|
|
7
|
+
import { BORDER_COLOR_DEFAULT_VALUE } from '../settings/defaultValues';
|
|
8
|
+
import { SwitchBlock } from '../';
|
|
9
|
+
import { AppBridgeBlock } from '@frontify/app-bridge';
|
|
10
|
+
|
|
11
|
+
describe('getBorderSettings', () => {
|
|
12
|
+
it('should return border settings without arguments', () => {
|
|
13
|
+
const borderSettings = getBorderSettings() as SwitchBlock;
|
|
14
|
+
|
|
15
|
+
expect(borderSettings).toHaveProperty('id', 'hasBorder');
|
|
16
|
+
expect(borderSettings).toHaveProperty('label', 'Border');
|
|
17
|
+
expect(borderSettings).toHaveProperty('type', 'switch');
|
|
18
|
+
expect(borderSettings).toHaveProperty('defaultValue', false);
|
|
19
|
+
expect(borderSettings.on?.[0]).toHaveProperty('id', 'borderSelection');
|
|
20
|
+
expect(borderSettings.on?.[0]).toHaveProperty('type', 'multiInput');
|
|
21
|
+
expect(borderSettings.on?.[0]).toHaveProperty('lastItemFullWidth', true);
|
|
22
|
+
expect(borderSettings.on?.[0]).toHaveProperty('layout', MultiInputLayout.Columns);
|
|
23
|
+
expect((borderSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[0]).toEqual({
|
|
24
|
+
id: 'borderStyle',
|
|
25
|
+
type: 'dropdown',
|
|
26
|
+
defaultValue: BorderStyle.Solid,
|
|
27
|
+
choices: [
|
|
28
|
+
{
|
|
29
|
+
value: BorderStyle.Solid,
|
|
30
|
+
label: BorderStyle.Solid,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: BorderStyle.Dotted,
|
|
34
|
+
label: BorderStyle.Dotted,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
value: BorderStyle.Dashed,
|
|
38
|
+
label: BorderStyle.Dashed,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
expect((borderSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[1]).toHaveProperty(
|
|
43
|
+
'id',
|
|
44
|
+
'borderWidth'
|
|
45
|
+
);
|
|
46
|
+
expect((borderSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[1]).toHaveProperty('type', 'input');
|
|
47
|
+
expect((borderSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[2]).toEqual({
|
|
48
|
+
id: 'borderColor',
|
|
49
|
+
type: 'colorInput',
|
|
50
|
+
defaultValue: BORDER_COLOR_DEFAULT_VALUE,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return border settings with custom id', () => {
|
|
55
|
+
expect(getBorderSettings({ id: 'Test' })).toHaveProperty('id', 'hasBorder_Test');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return border settings with custom color', () => {
|
|
59
|
+
const borderSettings = getBorderSettings({ defaultColor: { red: 255, green: 0, blue: 0 } }) as SwitchBlock;
|
|
60
|
+
expect((borderSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[2]).toEqual({
|
|
61
|
+
id: 'borderColor',
|
|
62
|
+
type: 'colorInput',
|
|
63
|
+
defaultValue: { red: 255, green: 0, blue: 0 },
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should return border settings with custom default value', () => {
|
|
68
|
+
const borderSettings = getBorderSettings({ defaultValue: true }) as SwitchBlock;
|
|
69
|
+
expect(borderSettings).toHaveProperty('defaultValue', true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should return border settings with custom switch label', () => {
|
|
73
|
+
const borderSettings = getBorderSettings({ switchLabel: 'mock' }) as SwitchBlock;
|
|
74
|
+
expect(borderSettings).toHaveProperty('switchLabel', 'mock');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Color,
|
|
5
|
+
MultiInputLayout,
|
|
6
|
+
SettingBlock,
|
|
7
|
+
appendUnit,
|
|
8
|
+
maximumNumericalOrPixelOrAutoRule,
|
|
9
|
+
numericalOrPixelRule,
|
|
10
|
+
} from '../';
|
|
11
|
+
import { BORDER_COLOR_DEFAULT_VALUE, BORDER_WIDTH_DEFAULT_VALUE } from './defaultValues';
|
|
12
|
+
import { BorderStyle } from './types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns border settings: border switch, border style, border width, border color
|
|
16
|
+
*
|
|
17
|
+
* @param options Options for the settings
|
|
18
|
+
* @param options.id Custom suffix for the setting ids
|
|
19
|
+
* @param options.switchLabel Label for the border switch
|
|
20
|
+
* @param options.defaultValue Default value for the border switch
|
|
21
|
+
* @returns {SettingBlock} Returns border settings
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
type BorderSettingsType = {
|
|
25
|
+
id?: string;
|
|
26
|
+
defaultValue?: boolean;
|
|
27
|
+
defaultColor?: Color;
|
|
28
|
+
switchLabel?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const getBorderSettings = (options?: BorderSettingsType): SettingBlock => {
|
|
32
|
+
const hasId = options?.id ? `hasBorder_${options.id}` : 'hasBorder';
|
|
33
|
+
const selectionId = options?.id ? `borderSelection_${options.id}` : 'borderSelection';
|
|
34
|
+
const styleId = options?.id ? `borderStyle_${options.id}` : 'borderStyle';
|
|
35
|
+
const widthId = options?.id ? `borderWidth_${options.id}` : 'borderWidth';
|
|
36
|
+
const colorId = options?.id ? `borderColor_${options.id}` : 'borderColor';
|
|
37
|
+
const defaultColor = options?.defaultColor || BORDER_COLOR_DEFAULT_VALUE;
|
|
38
|
+
const switchLabel = options?.switchLabel ? options.switchLabel : undefined;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
id: hasId,
|
|
42
|
+
label: 'Border',
|
|
43
|
+
type: 'switch',
|
|
44
|
+
switchLabel,
|
|
45
|
+
defaultValue: !!options?.defaultValue,
|
|
46
|
+
on: [
|
|
47
|
+
{
|
|
48
|
+
id: selectionId,
|
|
49
|
+
type: 'multiInput',
|
|
50
|
+
onChange: (bundle) => appendUnit(bundle, widthId),
|
|
51
|
+
layout: MultiInputLayout.Columns,
|
|
52
|
+
lastItemFullWidth: true,
|
|
53
|
+
blocks: [
|
|
54
|
+
{
|
|
55
|
+
id: styleId,
|
|
56
|
+
type: 'dropdown',
|
|
57
|
+
defaultValue: BorderStyle.Solid,
|
|
58
|
+
choices: [
|
|
59
|
+
{
|
|
60
|
+
value: BorderStyle.Solid,
|
|
61
|
+
label: BorderStyle.Solid,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
value: BorderStyle.Dotted,
|
|
65
|
+
label: BorderStyle.Dotted,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
value: BorderStyle.Dashed,
|
|
69
|
+
label: BorderStyle.Dashed,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: widthId,
|
|
75
|
+
type: 'input',
|
|
76
|
+
defaultValue: BORDER_WIDTH_DEFAULT_VALUE,
|
|
77
|
+
rules: [numericalOrPixelRule, maximumNumericalOrPixelOrAutoRule(500)],
|
|
78
|
+
placeholder: 'e.g. 3px',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: colorId,
|
|
82
|
+
type: 'colorInput',
|
|
83
|
+
defaultValue: defaultColor,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
off: [],
|
|
89
|
+
};
|
|
90
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { Radius, getBorderRadiusSettings } from '.';
|
|
5
|
+
import { SwitchBlock } from '..';
|
|
6
|
+
|
|
7
|
+
describe('getBorderRadiusSettings', () => {
|
|
8
|
+
it('should return border radius settings without arguments', () => {
|
|
9
|
+
const borderRadiusSettings = getBorderRadiusSettings() as SwitchBlock;
|
|
10
|
+
|
|
11
|
+
expect(borderRadiusSettings).toHaveProperty('id', 'hasRadius');
|
|
12
|
+
expect(borderRadiusSettings).toHaveProperty('label', 'Corner radius');
|
|
13
|
+
expect(borderRadiusSettings).toHaveProperty('type', 'switch');
|
|
14
|
+
expect(borderRadiusSettings).toHaveProperty('defaultValue', false);
|
|
15
|
+
expect(borderRadiusSettings.on?.[0]).toHaveProperty('id', 'radiusValue');
|
|
16
|
+
expect(borderRadiusSettings.on?.[0]).toHaveProperty('type', 'input');
|
|
17
|
+
expect(borderRadiusSettings.off?.[0]).toHaveProperty('id', 'radiusChoice');
|
|
18
|
+
expect(borderRadiusSettings.off?.[0]).toHaveProperty('type', 'segmentedControls');
|
|
19
|
+
expect(borderRadiusSettings.off?.[0]).toHaveProperty('defaultValue', Radius.None);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return border radius settings with custom id', () => {
|
|
23
|
+
expect(getBorderRadiusSettings({ id: 'Test' })).toHaveProperty('id', 'hasRadius_Test');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return border settings with custom default radius', () => {
|
|
27
|
+
const borderRadiusSettings = getBorderRadiusSettings({ defaultRadius: Radius.Large }) as SwitchBlock;
|
|
28
|
+
expect(borderRadiusSettings.off?.[0]).toHaveProperty('defaultValue', Radius.Large);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { SettingBlock, appendUnit, numericalOrPixelRule, presetCustomValue } from '../';
|
|
4
|
+
|
|
5
|
+
import { Radius, radiusStyleMap } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns border radius settings: border radius switch, radius slider, custom radius input
|
|
9
|
+
*
|
|
10
|
+
* @param options Options for the settings
|
|
11
|
+
* @param options.id Custom suffix for the setting ids
|
|
12
|
+
* @param options.dependentSettingId Id of setting which the border radius is dependent on
|
|
13
|
+
* @returns {SettingBlock} Returns border settings
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type BorderRadiusSettingsType = {
|
|
17
|
+
id?: string;
|
|
18
|
+
dependentSettingId?: string;
|
|
19
|
+
radiusStyleMap?: Record<Radius, string>;
|
|
20
|
+
defaultRadius?: Radius;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getBorderRadiusSlider = (id: string, defaultValue: Radius = Radius.None): SettingBlock => ({
|
|
24
|
+
id,
|
|
25
|
+
type: 'segmentedControls',
|
|
26
|
+
defaultValue,
|
|
27
|
+
choices: [
|
|
28
|
+
{
|
|
29
|
+
value: Radius.None,
|
|
30
|
+
label: 'None',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: Radius.Small,
|
|
34
|
+
label: 'S',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
value: Radius.Medium,
|
|
38
|
+
label: 'M',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
value: Radius.Large,
|
|
42
|
+
label: 'L',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const getBorderRadiusSettings = (options?: BorderRadiusSettingsType): SettingBlock => {
|
|
48
|
+
const hasId = options?.id ? `hasRadius_${options.id}` : 'hasRadius';
|
|
49
|
+
const valueId = options?.id ? `radiusValue_${options.id}` : 'radiusValue';
|
|
50
|
+
const choiceId = options?.id ? `radiusChoice_${options.id}` : 'radiusChoice';
|
|
51
|
+
const defaultValue = options?.defaultRadius || Radius.None;
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
id: hasId,
|
|
55
|
+
label: 'Corner radius',
|
|
56
|
+
type: 'switch',
|
|
57
|
+
switchLabel: 'Custom',
|
|
58
|
+
defaultValue: false,
|
|
59
|
+
info: 'Determining how rounded the corners are.',
|
|
60
|
+
show: (bundle) => (options?.dependentSettingId ? !!bundle.getBlock(options.dependentSettingId)?.value : true),
|
|
61
|
+
onChange: (bundle) => presetCustomValue(bundle, choiceId, valueId, options?.radiusStyleMap || radiusStyleMap),
|
|
62
|
+
on: [
|
|
63
|
+
{
|
|
64
|
+
id: valueId,
|
|
65
|
+
type: 'input',
|
|
66
|
+
placeholder: 'e.g. 10px',
|
|
67
|
+
rules: [numericalOrPixelRule],
|
|
68
|
+
onChange: (bundle) => appendUnit(bundle, valueId),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
off: [getBorderRadiusSlider(choiceId, defaultValue)],
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { MultiInputBlock, MultiInputLayout } from '@frontify/sidebar-settings';
|
|
5
|
+
import { Radius, getExtendedBorderRadiusSettings } from '.';
|
|
6
|
+
import { SwitchBlock } from '..';
|
|
7
|
+
import { AppBridgeBlock } from '@frontify/app-bridge';
|
|
8
|
+
|
|
9
|
+
describe('getBorderRadiusExtendedSettings', () => {
|
|
10
|
+
it('should return extended border radius settings without arguments', () => {
|
|
11
|
+
const extendedBorderRadiusSettings = getExtendedBorderRadiusSettings() as SwitchBlock;
|
|
12
|
+
|
|
13
|
+
expect(extendedBorderRadiusSettings).toHaveProperty('id', 'hasExtendedCustomRadius');
|
|
14
|
+
expect(extendedBorderRadiusSettings).toHaveProperty('label', 'Corner radius');
|
|
15
|
+
expect(extendedBorderRadiusSettings).toHaveProperty('type', 'switch');
|
|
16
|
+
expect(extendedBorderRadiusSettings).toHaveProperty('defaultValue', false);
|
|
17
|
+
expect(extendedBorderRadiusSettings.on?.[0]).toHaveProperty('id', 'extendedRadiusValue');
|
|
18
|
+
expect(extendedBorderRadiusSettings.on?.[0]).toHaveProperty('type', 'multiInput');
|
|
19
|
+
expect(extendedBorderRadiusSettings.on?.[0]).toHaveProperty('layout', MultiInputLayout.Columns);
|
|
20
|
+
|
|
21
|
+
expect((extendedBorderRadiusSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[0]).toHaveProperty(
|
|
22
|
+
'id',
|
|
23
|
+
'extendedRadiusTopLeft'
|
|
24
|
+
);
|
|
25
|
+
expect((extendedBorderRadiusSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[1]).toHaveProperty(
|
|
26
|
+
'id',
|
|
27
|
+
'extendedRadiusTopRight'
|
|
28
|
+
);
|
|
29
|
+
expect((extendedBorderRadiusSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[2]).toHaveProperty(
|
|
30
|
+
'id',
|
|
31
|
+
'extendedRadiusBottomLeft'
|
|
32
|
+
);
|
|
33
|
+
expect((extendedBorderRadiusSettings.on?.[0] as MultiInputBlock<AppBridgeBlock>).blocks[3]).toHaveProperty(
|
|
34
|
+
'id',
|
|
35
|
+
'extendedRadiusBottomRight'
|
|
36
|
+
);
|
|
37
|
+
expect(extendedBorderRadiusSettings.off?.[0]).toHaveProperty('id', 'extendedRadiusChoice');
|
|
38
|
+
expect(extendedBorderRadiusSettings.off?.[0]).toHaveProperty('type', 'segmentedControls');
|
|
39
|
+
expect(extendedBorderRadiusSettings.off?.[0]).toHaveProperty('defaultValue', Radius.None);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return extended border radius settings with id', () => {
|
|
43
|
+
expect(getExtendedBorderRadiusSettings({ id: 'Test' })).toHaveProperty('id', 'hasExtendedCustomRadius_Test');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should return extended border settings with custom default value', () => {
|
|
47
|
+
const extendedBorderRadiusSettings = getExtendedBorderRadiusSettings({
|
|
48
|
+
defaultValue: Radius.Large,
|
|
49
|
+
}) as SwitchBlock;
|
|
50
|
+
expect(extendedBorderRadiusSettings.off?.[0]).toHaveProperty('defaultValue', Radius.Large);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { MultiInputLayout, SettingBlock, appendUnit, numericalOrPixelRule, presetCustomValue } from '../';
|
|
4
|
+
import { getBorderRadiusSlider } from './borderRadius';
|
|
5
|
+
import { Radius, radiusStyleMap } from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns border radius settings: border radius switch, radius slider, custom radius inputs for every corner
|
|
9
|
+
*
|
|
10
|
+
* @param options Options for the settings
|
|
11
|
+
* @param options.id Custom suffix for the setting ids
|
|
12
|
+
* @param options.dependentSettingId Id of setting which the border radius is dependent on
|
|
13
|
+
* @returns {SettingBlock} Returns border settings
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
type BorderRadiusSettingsType = {
|
|
17
|
+
id?: string;
|
|
18
|
+
dependentSettingId?: string;
|
|
19
|
+
defaultValue?: Radius;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getExtendedBorderRadiusSettings = (options?: BorderRadiusSettingsType): SettingBlock => {
|
|
23
|
+
const hasId = options?.id ? `hasExtendedCustomRadius_${options.id}` : 'hasExtendedCustomRadius';
|
|
24
|
+
const valueId = options?.id ? `extendedRadiusValue_${options.id}` : 'extendedRadiusValue';
|
|
25
|
+
const choiceId = options?.id ? `extendedRadiusChoice_${options.id}` : 'extendedRadiusChoice';
|
|
26
|
+
const topLeftId = options?.id ? `extendedRadiusTopLeft_${options.id}` : 'extendedRadiusTopLeft';
|
|
27
|
+
const topRightId = options?.id ? `extendedRadiusTopRight_${options.id}` : 'extendedRadiusTopRight';
|
|
28
|
+
const bottomLeftId = options?.id ? `extendedRadiusBottomLeft_${options.id}` : 'extendedRadiusBottomLeft';
|
|
29
|
+
const bottomRightId = options?.id ? `extendedRadiusBottomRight_${options.id}` : 'extendedRadiusBottomRight';
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
id: hasId,
|
|
33
|
+
label: 'Corner radius',
|
|
34
|
+
type: 'switch',
|
|
35
|
+
switchLabel: 'Custom',
|
|
36
|
+
defaultValue: false,
|
|
37
|
+
info: 'Determining how rounded the corners are.',
|
|
38
|
+
show: (bundle) => (options?.dependentSettingId ? !!bundle.getBlock(options.dependentSettingId)?.value : true),
|
|
39
|
+
onChange: (bundle) => {
|
|
40
|
+
presetCustomValue(bundle, choiceId, topLeftId, radiusStyleMap);
|
|
41
|
+
presetCustomValue(bundle, choiceId, topRightId, radiusStyleMap);
|
|
42
|
+
presetCustomValue(bundle, choiceId, bottomLeftId, radiusStyleMap);
|
|
43
|
+
presetCustomValue(bundle, choiceId, bottomRightId, radiusStyleMap);
|
|
44
|
+
},
|
|
45
|
+
on: [
|
|
46
|
+
{
|
|
47
|
+
id: valueId,
|
|
48
|
+
type: 'multiInput',
|
|
49
|
+
layout: MultiInputLayout.Columns,
|
|
50
|
+
blocks: [
|
|
51
|
+
{
|
|
52
|
+
id: topLeftId,
|
|
53
|
+
type: 'input',
|
|
54
|
+
label: 'Top Left',
|
|
55
|
+
rules: [numericalOrPixelRule],
|
|
56
|
+
onChange: (bundle) => appendUnit(bundle, topLeftId),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: topRightId,
|
|
60
|
+
type: 'input',
|
|
61
|
+
label: 'Top Right',
|
|
62
|
+
rules: [numericalOrPixelRule],
|
|
63
|
+
onChange: (bundle) => appendUnit(bundle, topRightId),
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: bottomLeftId,
|
|
67
|
+
type: 'input',
|
|
68
|
+
label: 'Bottom Left',
|
|
69
|
+
rules: [numericalOrPixelRule],
|
|
70
|
+
onChange: (bundle) => appendUnit(bundle, bottomLeftId),
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: bottomRightId,
|
|
74
|
+
type: 'input',
|
|
75
|
+
label: 'Bottom Right',
|
|
76
|
+
rules: [numericalOrPixelRule],
|
|
77
|
+
onChange: (bundle) => appendUnit(bundle, bottomRightId),
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
off: [getBorderRadiusSlider(choiceId, options?.defaultValue)],
|
|
83
|
+
};
|
|
84
|
+
};
|