@kitconcept/volto-light-theme 8.0.0-alpha.3 → 8.0.0-alpha.30

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 (200) hide show
  1. package/.changelog.draft +6 -9
  2. package/CHANGELOG.md +310 -0
  3. package/locales/af/LC_MESSAGES/volto.po +645 -0
  4. package/locales/ar/LC_MESSAGES/volto.po +645 -0
  5. package/locales/bg/LC_MESSAGES/volto.po +645 -0
  6. package/locales/bn/LC_MESSAGES/volto.po +645 -0
  7. package/locales/ca/LC_MESSAGES/volto.po +645 -0
  8. package/locales/cs/LC_MESSAGES/volto.po +645 -0
  9. package/locales/cy/LC_MESSAGES/volto.po +645 -0
  10. package/locales/da/LC_MESSAGES/volto.po +645 -0
  11. package/locales/de/LC_MESSAGES/volto.po +83 -167
  12. package/locales/el/LC_MESSAGES/volto.po +645 -0
  13. package/locales/en/LC_MESSAGES/volto.po +30 -115
  14. package/locales/en_AU/LC_MESSAGES/volto.po +645 -0
  15. package/locales/en_GB/LC_MESSAGES/volto.po +645 -0
  16. package/locales/eo/LC_MESSAGES/volto.po +645 -0
  17. package/locales/es/LC_MESSAGES/volto.po +75 -160
  18. package/locales/et/LC_MESSAGES/volto.po +645 -0
  19. package/locales/eu/LC_MESSAGES/volto.po +59 -125
  20. package/locales/fa/LC_MESSAGES/volto.po +645 -0
  21. package/locales/fi/LC_MESSAGES/volto.po +645 -0
  22. package/locales/fr/LC_MESSAGES/volto.po +645 -0
  23. package/locales/fu/LC_MESSAGES/volto.po +645 -0
  24. package/locales/ga/LC_MESSAGES/volto.po +645 -0
  25. package/locales/gl/LC_MESSAGES/volto.po +645 -0
  26. package/locales/he/LC_MESSAGES/volto.po +645 -0
  27. package/locales/hi/LC_MESSAGES/volto.po +645 -0
  28. package/locales/hr/LC_MESSAGES/volto.po +645 -0
  29. package/locales/hu/LC_MESSAGES/volto.po +645 -0
  30. package/locales/hy/LC_MESSAGES/volto.po +645 -0
  31. package/locales/id/LC_MESSAGES/volto.po +645 -0
  32. package/locales/it/LC_MESSAGES/volto.po +645 -0
  33. package/locales/ja/LC_MESSAGES/volto.po +645 -0
  34. package/locales/ka/LC_MESSAGES/volto.po +645 -0
  35. package/locales/kn/LC_MESSAGES/volto.po +645 -0
  36. package/locales/ko/LC_MESSAGES/volto.po +645 -0
  37. package/locales/lt/LC_MESSAGES/volto.po +645 -0
  38. package/locales/lv/LC_MESSAGES/volto.po +645 -0
  39. package/locales/mi/LC_MESSAGES/volto.po +645 -0
  40. package/locales/mk_MK/LC_MESSAGES/volto.po +645 -0
  41. package/locales/ms/LC_MESSAGES/volto.po +645 -0
  42. package/locales/mt/LC_MESSAGES/volto.po +645 -0
  43. package/locales/my/LC_MESSAGES/volto.po +645 -0
  44. package/locales/nl/LC_MESSAGES/volto.po +645 -0
  45. package/locales/nl_BE/LC_MESSAGES/volto.po +645 -0
  46. package/locales/nn/LC_MESSAGES/volto.po +645 -0
  47. package/locales/no/LC_MESSAGES/volto.po +645 -0
  48. package/locales/pl/LC_MESSAGES/volto.po +645 -0
  49. package/locales/pt/LC_MESSAGES/volto.po +645 -0
  50. package/locales/pt_BR/LC_MESSAGES/volto.po +38 -123
  51. package/locales/rm/LC_MESSAGES/volto.po +645 -0
  52. package/locales/ro/LC_MESSAGES/volto.po +645 -0
  53. package/locales/ru/LC_MESSAGES/volto.po +645 -0
  54. package/locales/sk/LC_MESSAGES/volto.po +645 -0
  55. package/locales/sl/LC_MESSAGES/volto.po +645 -0
  56. package/locales/sm/LC_MESSAGES/volto.po +645 -0
  57. package/locales/sq/LC_MESSAGES/volto.po +645 -0
  58. package/locales/sr/LC_MESSAGES/volto.po +645 -0
  59. package/locales/sr_Cyrl/LC_MESSAGES/volto.po +645 -0
  60. package/locales/sr_Latn/LC_MESSAGES/volto.po +645 -0
  61. package/locales/sv/LC_MESSAGES/volto.po +645 -0
  62. package/locales/sw/LC_MESSAGES/volto.po +645 -0
  63. package/locales/ta/LC_MESSAGES/volto.po +645 -0
  64. package/locales/te/LC_MESSAGES/volto.po +645 -0
  65. package/locales/th/LC_MESSAGES/volto.po +645 -0
  66. package/locales/tl/LC_MESSAGES/volto.po +645 -0
  67. package/locales/to/LC_MESSAGES/volto.po +645 -0
  68. package/locales/tr/LC_MESSAGES/volto.po +645 -0
  69. package/locales/uk/LC_MESSAGES/volto.po +645 -0
  70. package/locales/vi/LC_MESSAGES/volto.po +645 -0
  71. package/locales/volto.pot +31 -116
  72. package/locales/zh_CN/LC_MESSAGES/volto.po +645 -0
  73. package/locales/zh_HK/LC_MESSAGES/volto.po +645 -0
  74. package/locales/zh_TW/LC_MESSAGES/volto.po +645 -0
  75. package/package.json +7 -4
  76. package/src/__mocks__/semantic-ui-react.ts +31 -0
  77. package/src/components/Blocks/Block/EditBlockWrapper.jsx +9 -3
  78. package/src/components/Blocks/Button/schema.js +12 -0
  79. package/src/components/Blocks/EventCalendar/Search/components/EventTemplate.tsx +1 -1
  80. package/src/components/Blocks/Image/Edit.jsx +9 -32
  81. package/src/components/Blocks/Image/View.jsx +9 -26
  82. package/src/components/Blocks/Image/adapter.js +28 -14
  83. package/src/components/Blocks/Image/adapter.test.js +156 -0
  84. package/src/components/Blocks/Image/schema.js +21 -7
  85. package/src/components/Blocks/Listing/DefaultTemplate.jsx +12 -6
  86. package/src/components/Blocks/Listing/GridTemplate.jsx +17 -7
  87. package/src/components/Blocks/Listing/ListingBody.jsx +4 -1
  88. package/src/components/Blocks/Listing/SummaryTemplate.jsx +17 -7
  89. package/src/components/Blocks/Maps/MapsSidebar.jsx +68 -0
  90. package/src/components/Blocks/Maps/View.jsx +37 -0
  91. package/src/components/Blocks/Maps/adapter.js +27 -0
  92. package/src/components/Blocks/Maps/adapter.test.js +63 -0
  93. package/src/components/Blocks/Maps/schema.js +42 -2
  94. package/src/components/Blocks/Separator/schema.js +12 -0
  95. package/src/components/Blocks/Teaser/DefaultBody.tsx +35 -6
  96. package/src/components/Blocks/Video/VideoSidebar.jsx +68 -0
  97. package/src/components/Blocks/Video/View.jsx +38 -0
  98. package/src/components/Blocks/Video/adapter.js +28 -0
  99. package/src/components/Blocks/Video/adapter.test.js +63 -0
  100. package/src/components/Blocks/Video/schema.js +42 -2
  101. package/src/components/Blocks/schema.ts +69 -0
  102. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +128 -0
  103. package/src/components/Breadcrumbs/Breadcrumbs.tsx +117 -0
  104. package/src/components/Caption/Caption.test.tsx +31 -0
  105. package/src/components/Caption/{Caption.jsx → Caption.tsx} +14 -21
  106. package/src/components/Footer/ColumnLinks.tsx +2 -2
  107. package/src/components/Footer/Footer.tsx +2 -2
  108. package/src/components/Footer/slots/Colophon.tsx +13 -1
  109. package/src/components/Footer/slots/CoreFooter.tsx +4 -2
  110. package/src/components/Footer/slots/FollowUsLogoAndLinks.tsx +12 -23
  111. package/src/components/Header/Header.tsx +3 -3
  112. package/src/components/LanguageSelector/LanguageSelector.tsx +91 -0
  113. package/src/components/MobileNavigation/MobileNavigation.jsx +11 -9
  114. package/src/components/Navigation/Navigation.test.tsx +176 -0
  115. package/src/components/Navigation/{Navigation.jsx → Navigation.tsx} +89 -42
  116. package/src/components/StickyMenu/MobileCarouselArrowButton.tsx +81 -0
  117. package/src/components/StickyMenu/MobileStickyMenu.tsx +76 -0
  118. package/src/components/Summary/DefaultSummary.tsx +10 -3
  119. package/src/components/Summary/EventSummary.tsx +10 -3
  120. package/src/components/Summary/FileSummary.tsx +10 -3
  121. package/src/components/Summary/NewsItemSummary.tsx +10 -3
  122. package/src/components/Summary/PersonSummary.tsx +10 -3
  123. package/src/components/Summary/Summary.stories.tsx +46 -30
  124. package/src/components/Tags/Tags.test.tsx +71 -0
  125. package/src/components/Tags/{Tags.jsx → Tags.tsx} +9 -25
  126. package/src/components/Theme/EventView.jsx +4 -4
  127. package/src/components/Theme/ImageView.jsx +8 -1
  128. package/src/components/Theme/NewsItemView.jsx +4 -4
  129. package/src/components/Theme/RenderBlocksV2.jsx +38 -15
  130. package/src/components/Widgets/ColorSwatch.stories.tsx +197 -0
  131. package/src/components/Widgets/ColorSwatch.test.tsx +188 -0
  132. package/src/components/Widgets/ColorSwatch.tsx +77 -39
  133. package/src/components/Widgets/ObjectList.tsx +37 -27
  134. package/src/components/Widgets/SoftTextWidget.tsx +129 -0
  135. package/src/components/Widgets/SoftTextareaWidget.tsx +118 -0
  136. package/src/components/Widgets/ThemeColorSwatch.tsx +5 -9
  137. package/src/config/blocks.tsx +83 -28
  138. package/src/config/classExtenders.ts +11 -10
  139. package/src/config/settings.ts +6 -0
  140. package/src/config/slots.ts +7 -0
  141. package/src/config/widgets.ts +5 -9
  142. package/src/customizations/volto/components/manage/Blocks/Maps/MapsSidebar.jsx +10 -0
  143. package/src/customizations/volto/components/manage/Blocks/Maps/View.jsx +10 -0
  144. package/src/customizations/volto/components/manage/Blocks/Video/VideoSidebar.jsx +10 -0
  145. package/src/customizations/volto/components/manage/Blocks/Video/View.jsx +10 -0
  146. package/src/customizations/volto/components/manage/DragDropList/DragDropList.jsx +263 -0
  147. package/src/customizations/volto/components/theme/LanguageSelector/LanguageSelector.tsx +10 -0
  148. package/src/helpers/styleDefinitions.test.tsx +30 -0
  149. package/src/helpers/styleDefinitions.ts +49 -0
  150. package/src/helpers/useLiveData.ts +7 -2
  151. package/src/index.ts +15 -0
  152. package/src/internalChecks.test.ts +94 -0
  153. package/src/primitives/Card/Card.stories.tsx +4 -1
  154. package/src/primitives/Card/Card.test.tsx +11 -33
  155. package/src/primitives/Card/Card.tsx +37 -44
  156. package/src/primitives/IconLinkList.tsx +53 -52
  157. package/src/primitives/LinkIconButton.tsx +52 -0
  158. package/src/reducers/errorContext.ts +14 -0
  159. package/src/reducers/index.ts +7 -0
  160. package/src/theme/_bgcolor-blocks-layout.scss +48 -46
  161. package/src/theme/_content.scss +12 -13
  162. package/src/theme/_export_import.scss +94 -0
  163. package/src/theme/_footer.scss +131 -64
  164. package/src/theme/_header.scss +25 -5
  165. package/src/theme/_insets.scss +1 -1
  166. package/src/theme/_layout.scss +41 -77
  167. package/src/theme/_mobile-sticky-menu.scss +92 -0
  168. package/src/theme/_search-page.scss +250 -0
  169. package/src/theme/_typo-custom.scss +24 -8
  170. package/src/theme/_variables.scss +40 -4
  171. package/src/theme/_widgets.scss +6 -17
  172. package/src/theme/blocks/_accordion.scss +11 -4
  173. package/src/theme/blocks/_form.scss +350 -0
  174. package/src/theme/blocks/_grid.scss +10 -77
  175. package/src/theme/blocks/_highlight.scss +10 -7
  176. package/src/theme/blocks/_image.scss +99 -184
  177. package/src/theme/blocks/_listing.scss +61 -128
  178. package/src/theme/blocks/_maps.scss +60 -34
  179. package/src/theme/blocks/_search.scss +3 -4
  180. package/src/theme/blocks/_table.scss +1 -0
  181. package/src/theme/blocks/_teaser.scss +7 -117
  182. package/src/theme/blocks/_toc.scss +2 -1
  183. package/src/theme/card.scss +136 -69
  184. package/src/theme/main.scss +4 -0
  185. package/src/theme/notfound.scss +2 -0
  186. package/src/theme/person.scss +7 -1
  187. package/src/theme/sticky-menu.scss +7 -5
  188. package/src/transforms/to6.ts +5 -49
  189. package/src/transforms/to8.test.js +201 -0
  190. package/src/transforms/to8.ts +109 -0
  191. package/src/types.d.ts +1 -0
  192. package/vitest.config.mjs +28 -3
  193. package/razzle.extend.js +0 -38
  194. package/src/components/Blocks/schema.js +0 -44
  195. package/src/components/Breadcrumbs/Breadcrumbs.jsx +0 -118
  196. package/src/components/Widgets/AlignWidget.tsx +0 -84
  197. package/src/components/Widgets/BlockAlignment.tsx +0 -88
  198. package/src/components/Widgets/BlockWidth.tsx +0 -101
  199. package/src/components/Widgets/Buttons.tsx +0 -167
  200. package/src/components/Widgets/Size.tsx +0 -78
@@ -1,84 +0,0 @@
1
- import React from 'react';
2
- import { defineMessages, useIntl } from 'react-intl';
3
- import ButtonsWidget, {
4
- type ActionInfo,
5
- type ButtonsWidgetProps,
6
- } from './Buttons';
7
- import imageLeftSVG from '@plone/volto/icons/image-left.svg';
8
- import imageRightSVG from '@plone/volto/icons/image-right.svg';
9
- import imageFitSVG from '@plone/volto/icons/image-fit.svg';
10
- import imageNarrowSVG from '@plone/volto/icons/image-narrow.svg';
11
- import imageWideSVG from '@plone/volto/icons/image-wide.svg';
12
- import imageFullSVG from '@plone/volto/icons/image-full.svg';
13
- import type { IntlShape } from 'react-intl';
14
-
15
- const messages = defineMessages({
16
- left: {
17
- id: 'Left',
18
- defaultMessage: 'Left',
19
- },
20
- right: {
21
- id: 'Right',
22
- defaultMessage: 'Right',
23
- },
24
- center: {
25
- id: 'Center',
26
- defaultMessage: 'Center',
27
- },
28
- narrow: {
29
- id: 'Narrow',
30
- defaultMessage: 'Narrow',
31
- },
32
- wide: {
33
- id: 'Wide',
34
- defaultMessage: 'Wide',
35
- },
36
- full: {
37
- id: 'Full',
38
- defaultMessage: 'Full',
39
- },
40
- });
41
-
42
- export const defaultActionsInfo = ({
43
- intl,
44
- }: {
45
- intl: IntlShape;
46
- }): Record<string, ActionInfo> => ({
47
- left: [imageLeftSVG, intl.formatMessage(messages.left)],
48
- center: [imageFitSVG, intl.formatMessage(messages.center)],
49
- right: [imageRightSVG, intl.formatMessage(messages.right)],
50
- narrow: [imageNarrowSVG, intl.formatMessage(messages.narrow)],
51
- wide: [imageWideSVG, intl.formatMessage(messages.wide)],
52
- full: [imageFullSVG, intl.formatMessage(messages.full)],
53
- });
54
-
55
- type AlignWidgetProps = ButtonsWidgetProps & {
56
- defaultAction?: string;
57
- };
58
-
59
- const AlignWidget = (props: AlignWidgetProps) => {
60
- const intl = useIntl();
61
-
62
- const {
63
- actions = ['left', 'center', 'right', 'full'],
64
- actionsInfoMap,
65
- default: defaultValue,
66
- defaultAction,
67
- } = props;
68
-
69
- const actionsInfo = {
70
- ...defaultActionsInfo({ intl }),
71
- ...actionsInfoMap,
72
- };
73
-
74
- return (
75
- <ButtonsWidget
76
- {...props}
77
- actions={actions}
78
- actionsInfoMap={actionsInfo}
79
- default={defaultValue ?? defaultAction ?? 'center'}
80
- />
81
- );
82
- };
83
-
84
- export default AlignWidget;
@@ -1,88 +0,0 @@
1
- import React from 'react';
2
- import { defineMessages, useIntl } from 'react-intl';
3
- import ButtonsWidget, {
4
- type ActionInfo,
5
- type ButtonsWidgetProps,
6
- } from './Buttons';
7
- import imageFitSVG from '@plone/volto/icons/image-fit.svg';
8
- import imageLeftSVG from '@plone/volto/icons/image-left.svg';
9
- import imageRightSVG from '@plone/volto/icons/image-right.svg';
10
- import type { IntlShape } from 'react-intl';
11
- import type { StyleDefinition } from '@plone/types';
12
-
13
- const messages = defineMessages({
14
- left: {
15
- id: 'Left',
16
- defaultMessage: 'Left',
17
- },
18
- right: {
19
- id: 'Right',
20
- defaultMessage: 'Right',
21
- },
22
- center: {
23
- id: 'Center',
24
- defaultMessage: 'Center',
25
- },
26
- });
27
-
28
- export const defaultActionsInfo = ({
29
- intl,
30
- }: {
31
- intl: IntlShape;
32
- }): Record<string, ActionInfo> => ({
33
- left: [imageLeftSVG, intl.formatMessage(messages.left)],
34
- right: [imageRightSVG, intl.formatMessage(messages.right)],
35
- center: [imageFitSVG, intl.formatMessage(messages.center)],
36
- });
37
-
38
- const DEFAULT_ACTIONS: StyleDefinition[] = [
39
- {
40
- style: {
41
- '--block-alignment': 'var(--align-left)',
42
- },
43
- name: 'left',
44
- label: 'Left',
45
- },
46
- {
47
- style: {
48
- '--block-alignment': 'var(--align-center)',
49
- },
50
- name: 'center',
51
- label: 'Center',
52
- },
53
- {
54
- style: {
55
- '--block-alignment': 'var(--align-right)',
56
- },
57
- name: 'right',
58
- label: 'Right',
59
- },
60
- ];
61
-
62
- const BlockAlignmentWidget = (props: ButtonsWidgetProps) => {
63
- const intl = useIntl();
64
-
65
- const { actions = DEFAULT_ACTIONS, actionsInfoMap, filterActions } = props;
66
- const filteredActions =
67
- filterActions && filterActions.length > 0
68
- ? actions.filter((action) => {
69
- const actionName = typeof action === 'string' ? action : action.name;
70
- return filterActions.includes(actionName);
71
- })
72
- : actions;
73
-
74
- const actionsInfo = {
75
- ...defaultActionsInfo({ intl }),
76
- ...actionsInfoMap,
77
- };
78
-
79
- return (
80
- <ButtonsWidget
81
- {...props}
82
- actions={filteredActions}
83
- actionsInfoMap={actionsInfo}
84
- />
85
- );
86
- };
87
-
88
- export default BlockAlignmentWidget;
@@ -1,101 +0,0 @@
1
- import React from 'react';
2
- import { defineMessages, useIntl } from 'react-intl';
3
- import type { IntlShape } from 'react-intl';
4
- import ButtonsWidget, {
5
- type ActionInfo,
6
- type ButtonsWidgetProps,
7
- } from './Buttons';
8
- import imageFitSVG from '@plone/volto/icons/image-fit.svg';
9
- import imageNarrowSVG from '@plone/volto/icons/image-narrow.svg';
10
- import imageWideSVG from '@plone/volto/icons/image-wide.svg';
11
- import imageFullSVG from '@plone/volto/icons/image-full.svg';
12
- import type { StyleDefinition } from '@plone/types';
13
-
14
- const messages = defineMessages({
15
- narrow: {
16
- id: 'Narrow',
17
- defaultMessage: 'Narrow',
18
- },
19
- default: {
20
- id: 'Default',
21
- defaultMessage: 'Default',
22
- },
23
- layout: {
24
- id: 'Layout',
25
- defaultMessage: 'Layout',
26
- },
27
- full: {
28
- id: 'Full',
29
- defaultMessage: 'Full',
30
- },
31
- });
32
-
33
- export const defaultActionsInfo = ({
34
- intl,
35
- }: {
36
- intl: IntlShape;
37
- }): Record<string, ActionInfo> => ({
38
- narrow: [imageNarrowSVG, intl.formatMessage(messages.narrow)],
39
- default: [imageFitSVG, intl.formatMessage(messages.default)],
40
- layout: [imageWideSVG, intl.formatMessage(messages.layout)],
41
- full: [imageFullSVG, intl.formatMessage(messages.full)],
42
- });
43
-
44
- const DEFAULT_ACTIONS: StyleDefinition[] = [
45
- {
46
- style: {
47
- '--block-width': 'var(--narrow-container-width)',
48
- },
49
- name: 'narrow',
50
- label: 'Narrow',
51
- },
52
- {
53
- style: {
54
- '--block-width': 'var(--default-container-width)',
55
- },
56
- name: 'default',
57
- label: 'Default',
58
- },
59
- {
60
- style: {
61
- '--block-width': 'var(--layout-container-width)',
62
- },
63
- name: 'layout',
64
- label: 'Layout',
65
- },
66
- {
67
- style: {
68
- '--block-width': 'unset',
69
- },
70
- name: 'full',
71
- label: 'Full',
72
- },
73
- ];
74
-
75
- const BlockWidthWidget = (props: ButtonsWidgetProps) => {
76
- const intl = useIntl();
77
-
78
- const { actions = DEFAULT_ACTIONS, actionsInfoMap, filterActions } = props;
79
- const filteredActions =
80
- filterActions && filterActions.length > 0
81
- ? actions.filter((action) => {
82
- const actionName = typeof action === 'string' ? action : action.name;
83
- return filterActions.includes(actionName);
84
- })
85
- : actions;
86
-
87
- const actionsInfo = {
88
- ...defaultActionsInfo({ intl }),
89
- ...actionsInfoMap,
90
- };
91
-
92
- return (
93
- <ButtonsWidget
94
- {...props}
95
- actions={filteredActions}
96
- actionsInfoMap={actionsInfo}
97
- />
98
- );
99
- };
100
-
101
- export default BlockWidthWidget;
@@ -1,167 +0,0 @@
1
- import React from 'react';
2
- import FormFieldWrapper from '@plone/volto/components/manage/Widgets/FormFieldWrapper';
3
- import Icon from '@plone/volto/components/theme/Icon/Icon';
4
- import { RadioGroup } from '@plone/components';
5
- import { Radio } from 'react-aria-components';
6
- import isEqual from 'lodash/isEqual';
7
- import type { StyleDefinition } from '@plone/types';
8
-
9
- /**
10
- * A tuple that has an icon in the first element and a i18n string in the second.
11
- */
12
- export type ActionInfo = [React.ReactElement<any>, string] | [string, string];
13
-
14
- type ActionValue = string | Record<`--${string}`, string>;
15
-
16
- export type ButtonsWidgetProps = {
17
- /**
18
- * Unique identifier for the widget.
19
- */
20
- id: string;
21
-
22
- /**
23
- * Callback function to handle changes.
24
- */
25
- onChange: (id: string, value: ActionValue) => void;
26
-
27
- /**
28
- * List of actions available for the widget.
29
- */
30
- actions?: Array<StyleDefinition | string>;
31
-
32
- /**
33
- * Map containing additional the information (icon and i18n string) for each action.
34
- */
35
- actionsInfoMap?: Record<string, ActionInfo>;
36
-
37
- /**
38
- * List of actions to be filtered out. In case that we don't want the default ones
39
- * we can filter them out.
40
- */
41
- filterActions?: string[];
42
-
43
- /**
44
- * Current value of the widget.
45
- */
46
- value?: ActionValue;
47
-
48
- /**
49
- * Default value of the widget.
50
- */
51
- default?: ActionValue;
52
-
53
- /**
54
- * Indicates if the widget is disabled.
55
- */
56
- disabled?: boolean;
57
-
58
- /**
59
- * Indicates if the widget is disabled (alternative flag for compatibility reasons).
60
- */
61
- isDisabled?: boolean;
62
- [key: string]: any;
63
- };
64
-
65
- type NormalizedAction = {
66
- name: string;
67
- value: ActionValue;
68
- };
69
-
70
- const ButtonsWidget = (props: ButtonsWidgetProps) => {
71
- const {
72
- disabled,
73
- id,
74
- onChange,
75
- actions = [],
76
- actionsInfoMap,
77
- value,
78
- isDisabled,
79
- default: defaultValue,
80
- } = props;
81
- const normalizedActions = React.useMemo<NormalizedAction[]>(
82
- () =>
83
- actions.map((action) =>
84
- typeof action === 'string'
85
- ? { name: action, value: action }
86
- : {
87
- name: action.name,
88
- value: action.style ?? action.name,
89
- },
90
- ),
91
- [actions],
92
- );
93
-
94
- const selectedActionName = React.useMemo(
95
- () =>
96
- normalizedActions.find((action) => isEqual(value, action.value))?.name,
97
- [normalizedActions, value],
98
- );
99
-
100
- const handleChange = React.useCallback(
101
- (selectedName: string) => {
102
- const selectedAction = normalizedActions.find(
103
- ({ name }) => name === selectedName,
104
- );
105
-
106
- if (selectedAction) {
107
- onChange(id, selectedAction.value);
108
- }
109
- },
110
- [id, normalizedActions, onChange],
111
- );
112
-
113
- React.useEffect(() => {
114
- if (!value && defaultValue) {
115
- const nextValue =
116
- typeof defaultValue === 'string'
117
- ? normalizedActions.find(({ name }) => name === defaultValue)
118
- ?.value ?? defaultValue
119
- : defaultValue;
120
-
121
- onChange(id, nextValue);
122
- }
123
- }, [defaultValue, id, normalizedActions, onChange, value]);
124
-
125
- return (
126
- <FormFieldWrapper {...props} className="widget">
127
- <RadioGroup
128
- aria-label={props.title || props.label || id}
129
- orientation="horizontal"
130
- value={selectedActionName}
131
- onChange={handleChange}
132
- isDisabled={disabled || isDisabled}
133
- className="buttons buttons-widget"
134
- >
135
- {normalizedActions.map((action) => {
136
- const actionInfo = actionsInfoMap?.[action.name];
137
- const [iconOrText, ariaLabel] = actionInfo ?? [
138
- action.name,
139
- action.name,
140
- ];
141
-
142
- return (
143
- <Radio
144
- key={action.name}
145
- aria-label={ariaLabel}
146
- value={action.name}
147
- className="buttons-widget-option"
148
- >
149
- {typeof iconOrText === 'string' ? (
150
- <div className="image-sizes-text">{iconOrText}</div>
151
- ) : (
152
- <Icon
153
- name={iconOrText}
154
- title={ariaLabel || action.name}
155
- size="24px"
156
- ariaHidden={true}
157
- />
158
- )}
159
- </Radio>
160
- );
161
- })}
162
- </RadioGroup>
163
- </FormFieldWrapper>
164
- );
165
- };
166
-
167
- export default ButtonsWidget;
@@ -1,78 +0,0 @@
1
- import { defineMessages, useIntl } from 'react-intl';
2
- import ButtonsWidget, {
3
- type ActionInfo,
4
- type ButtonsWidgetProps,
5
- } from './Buttons';
6
- import type { IntlShape } from 'react-intl';
7
- import type { StyleDefinition } from '@plone/types';
8
-
9
- const messages = defineMessages({
10
- s: {
11
- id: 'Small',
12
- defaultMessage: 'Small',
13
- },
14
- m: {
15
- id: 'Medium',
16
- defaultMessage: 'Medium',
17
- },
18
- l: {
19
- id: 'Large',
20
- defaultMessage: 'Large',
21
- },
22
- });
23
-
24
- export const defaultActionsInfo = ({
25
- intl,
26
- }: {
27
- intl: IntlShape;
28
- }): Record<string, ActionInfo> => ({
29
- s: ['S', intl.formatMessage(messages.s)],
30
- m: ['M', intl.formatMessage(messages.m)],
31
- l: ['L', intl.formatMessage(messages.l)],
32
- });
33
-
34
- const DEFAULT_ACTIONS: StyleDefinition[] = [
35
- {
36
- name: 's',
37
- label: 'Small',
38
- style: undefined,
39
- },
40
- {
41
- name: 'm',
42
- label: 'Medium',
43
- style: undefined,
44
- },
45
- {
46
- name: 'l',
47
- label: 'Large',
48
- style: undefined,
49
- },
50
- ];
51
-
52
- const SizeWidget = (props: ButtonsWidgetProps) => {
53
- const intl = useIntl();
54
-
55
- const { actions = DEFAULT_ACTIONS, actionsInfoMap, filterActions } = props;
56
- const filteredActions =
57
- filterActions && filterActions.length > 0
58
- ? actions.filter((action) => {
59
- const actionName = typeof action === 'string' ? action : action.name;
60
- return filterActions.includes(actionName);
61
- })
62
- : actions;
63
-
64
- const actionsInfo = {
65
- ...defaultActionsInfo({ intl }),
66
- ...actionsInfoMap,
67
- };
68
-
69
- return (
70
- <ButtonsWidget
71
- {...props}
72
- actions={filteredActions}
73
- actionsInfoMap={actionsInfo}
74
- />
75
- );
76
- };
77
-
78
- export default SizeWidget;