@reykjavik/hanna-react 0.10.140 → 0.10.142

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/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.10.142
8
+
9
+ _2024-11-28_
10
+
11
+ - feat: Deprecate `focus-visible` polyfill module; browser support is now good
12
+ - `Datepicker`:
13
+ - fix: Set `minDate` prop values to `T00:00` to allow manual min date input
14
+
15
+ ## 0.10.141
16
+
17
+ _2024-11-25_
18
+
19
+ - `DropdownButton`:
20
+ - feat: Support rendering `current` status of menu items
21
+ - feat: Add prop `onItemClick`
22
+
7
23
  ## 0.10.140
8
24
 
9
25
  _2024-11-21_
package/Datepicker.js CHANGED
@@ -116,6 +116,8 @@ const defaultDatepickerTexts = {
116
116
  const Datepicker = (props) => {
117
117
  const { placeholder, dateFormat, name, startDate, endDate, minDate, maxDate, isStartDate = false, isEndDate = false, onChange, datepickerExtraProps, inputRef, isoMode, texts, lang = props.localeCode, // eslint-disable-line deprecation/deprecation
118
118
  fieldWrapperProps, } = (0, FormField_js_1.groupFormFieldWrapperProps)(props);
119
+ // Make sure all minDates are at the start of the day
120
+ const minDateNormalized = minDate ? new Date(minDate.setHours(0, 0, 0, 0)) : undefined;
119
121
  const [value, setValue] = utils_js_1.useMixedControlState.raw(props.value || props.initialDate, // eslint-disable-line deprecation/deprecation
120
122
  props.defaultValue, 'value');
121
123
  /*
@@ -164,7 +166,7 @@ const Datepicker = (props) => {
164
166
  }, placeholderText: placeholder,
165
167
  // TODO: Implement this
166
168
  // selectsRange
167
- minDate: minDate, maxDate: maxDate, startDate: startDate, endDate: endDate, selectsStart: isStartDate, selectsEnd: isEndDate, formatWeekDay: (weekday) => weekday.charAt(0).toUpperCase(), showYearDropdown: true, scrollableYearDropdown: true, yearDropdownItemNumber: 15, showMonthDropdown: true }, inputProps, txts, datepickerExtraProps))));
169
+ minDate: minDateNormalized, maxDate: maxDate, startDate: startDate, endDate: endDate, selectsStart: isStartDate, selectsEnd: isEndDate, formatWeekDay: (weekday) => weekday.charAt(0).toUpperCase(), showYearDropdown: true, scrollableYearDropdown: true, yearDropdownItemNumber: 15, showMonthDropdown: true }, inputProps, txts, datepickerExtraProps))));
168
170
  } })));
169
171
  };
170
172
  exports.Datepicker = Datepicker;
@@ -12,12 +12,18 @@ export type DropdownButtonItem = MainMenu2Item & {
12
12
  export type DropdownButtonCustomItem = (props: {
13
13
  closeMenu: () => void;
14
14
  }) => React.ReactElement;
15
- export type DropdownButtonProps = Prefix<Omit<ButtonVariantProps, 'small'>, 'button'> & {
15
+ export type DropdownButtonProps = {
16
16
  label: string | NonNullable<React.ReactElement>;
17
17
  labelLong?: string;
18
+ items: Array<DropdownButtonItem | DropdownButtonCustomItem>;
19
+ /**
20
+ * NOTE: Clicking a MainMenu2 item will automatically close HannaUIState's
21
+ * "Hamburger menu" (a.k.a. "Mobile menu")
22
+ * … unless the `onItemClick` function explicitly returns `false`.
23
+ */
24
+ onItemClick?: (item: MainMenu2Item) => void | boolean;
18
25
  /** Default: `"seconcary"` */
19
26
  buttonType?: 'primary' | 'secondary';
20
- items: Array<DropdownButtonItem | DropdownButtonCustomItem>;
21
- } & WrapperElmProps<'details', 'open' | 'name'> & SSRSupportProps;
27
+ } & Prefix<Omit<ButtonVariantProps, 'small'>, 'button'> & WrapperElmProps<'details', 'open' | 'name'> & SSRSupportProps;
22
28
  export declare const DropdownButton: (props: DropdownButtonProps) => JSX.Element;
23
29
  export {};
package/DropdownButton.js CHANGED
@@ -24,7 +24,7 @@ const DropdownButton = (props) => {
24
24
  middleware: [(0, react_2.flip)(), (0, react_2.shift)()],
25
25
  whileElementsMounted: react_2.autoUpdate,
26
26
  });
27
- const { wrapperProps = {} } = props;
27
+ const { onItemClick, wrapperProps = {} } = props;
28
28
  return (react_1.default.createElement("details", Object.assign({}, wrapperProps, { className: (0, hanna_utils_1.modifiedClass)('DropdownButton', isOpen && 'open', wrapperProps.className), open: isOpen, onBlur: (e) => {
29
29
  var _a;
30
30
  if (!isHovering) {
@@ -68,9 +68,15 @@ const DropdownButton = (props) => {
68
68
  'data-icon': item.icon,
69
69
  'arial-label': item.labelLong,
70
70
  };
71
- return (react_1.default.createElement("li", { key: i, className: "DropdownButton__item" }, isBrowser && onClick ? (react_1.default.createElement("button", Object.assign({}, commonProps, { type: "button", "aria-controls": item.controlsId, onClick: (e) => {
72
- onClick(item) !== false && closeMenuStat();
73
- } }), label)) : href != null ? (react_1.default.createElement("a", Object.assign({}, commonProps, { href: href, hrefLang: item.hrefLang, target: item.target }), label)) : null));
71
+ const doRenderButton = isBrowser && (onClick || (onItemClick && href == null));
72
+ return (react_1.default.createElement("li", { key: i, className: (0, hanna_utils_1.modifiedClass)('DropdownButton__item', item.modifier), "aria-current": item.current || undefined }, doRenderButton ? (react_1.default.createElement("button", Object.assign({}, commonProps, { type: "button", "aria-controls": item.controlsId, onClick: () => {
73
+ const keepOpen1 = onClick && onClick(item) === false;
74
+ const keepOpen2 = onItemClick && onItemClick(item) === false;
75
+ !(keepOpen1 || keepOpen2) && closeMenuStat();
76
+ } }), label)) : href != null ? (react_1.default.createElement("a", Object.assign({}, commonProps, { href: href, hrefLang: item.hrefLang, target: item.target, onClick: () => {
77
+ const keepOpen = onItemClick && onItemClick(item) === false;
78
+ !keepOpen && closeMenuStat();
79
+ } }), label)) : null));
74
80
  }),
75
81
  react_1.default.createElement(FocusTrap_js_1.FocusTrap, { Tag: "li", depth: 2 }))));
76
82
  };
package/MainMenu2.js CHANGED
@@ -89,7 +89,8 @@ const getRenderers = (props) => {
89
89
  size: 'small',
90
90
  }
91
91
  : undefined;
92
- return (react_1.default.createElement(Tag, { key: key, className: (0, hanna_utils_1.modifiedClass)(`${classPrefix}item`, item.modifier), "aria-current": item.current || undefined }, isBrowser && (onClick || (href == null && onItemClick)) ? (react_1.default.createElement(ButtonTag, Object.assign({}, commonProps, { type: "button", "aria-controls": controlsId, onClick: () => {
92
+ const doRenderButton = isBrowser && (onClick || (onItemClick && href == null));
93
+ return (react_1.default.createElement(Tag, { key: key, className: (0, hanna_utils_1.modifiedClass)(`${classPrefix}item`, item.modifier), "aria-current": item.current || undefined }, doRenderButton ? (react_1.default.createElement(ButtonTag, Object.assign({}, commonProps, { type: "button", "aria-controls": controlsId, onClick: () => {
93
94
  const keepOpen1 = onClick && onClick(item) === false;
94
95
  const keepOpen2 = onItemClick && onItemClick(item) === false;
95
96
  !(keepOpen1 || keepOpen2) && closeMenu();
package/esm/Datepicker.js CHANGED
@@ -111,6 +111,8 @@ const defaultDatepickerTexts = {
111
111
  export const Datepicker = (props) => {
112
112
  const { placeholder, dateFormat, name, startDate, endDate, minDate, maxDate, isStartDate = false, isEndDate = false, onChange, datepickerExtraProps, inputRef, isoMode, texts, lang = props.localeCode, // eslint-disable-line deprecation/deprecation
113
113
  fieldWrapperProps, } = groupFormFieldWrapperProps(props);
114
+ // Make sure all minDates are at the start of the day
115
+ const minDateNormalized = minDate ? new Date(minDate.setHours(0, 0, 0, 0)) : undefined;
114
116
  const [value, setValue] = useMixedControlState.raw(props.value || props.initialDate, // eslint-disable-line deprecation/deprecation
115
117
  props.defaultValue, 'value');
116
118
  /*
@@ -159,7 +161,7 @@ export const Datepicker = (props) => {
159
161
  }, placeholderText: placeholder,
160
162
  // TODO: Implement this
161
163
  // selectsRange
162
- minDate: minDate, maxDate: maxDate, startDate: startDate, endDate: endDate, selectsStart: isStartDate, selectsEnd: isEndDate, formatWeekDay: (weekday) => weekday.charAt(0).toUpperCase(), showYearDropdown: true, scrollableYearDropdown: true, yearDropdownItemNumber: 15, showMonthDropdown: true }, inputProps, txts, datepickerExtraProps))));
164
+ minDate: minDateNormalized, maxDate: maxDate, startDate: startDate, endDate: endDate, selectsStart: isStartDate, selectsEnd: isEndDate, formatWeekDay: (weekday) => weekday.charAt(0).toUpperCase(), showYearDropdown: true, scrollableYearDropdown: true, yearDropdownItemNumber: 15, showMonthDropdown: true }, inputProps, txts, datepickerExtraProps))));
163
165
  } })));
164
166
  };
165
167
  export default Datepicker;
@@ -12,12 +12,18 @@ export type DropdownButtonItem = MainMenu2Item & {
12
12
  export type DropdownButtonCustomItem = (props: {
13
13
  closeMenu: () => void;
14
14
  }) => React.ReactElement;
15
- export type DropdownButtonProps = Prefix<Omit<ButtonVariantProps, 'small'>, 'button'> & {
15
+ export type DropdownButtonProps = {
16
16
  label: string | NonNullable<React.ReactElement>;
17
17
  labelLong?: string;
18
+ items: Array<DropdownButtonItem | DropdownButtonCustomItem>;
19
+ /**
20
+ * NOTE: Clicking a MainMenu2 item will automatically close HannaUIState's
21
+ * "Hamburger menu" (a.k.a. "Mobile menu")
22
+ * … unless the `onItemClick` function explicitly returns `false`.
23
+ */
24
+ onItemClick?: (item: MainMenu2Item) => void | boolean;
18
25
  /** Default: `"seconcary"` */
19
26
  buttonType?: 'primary' | 'secondary';
20
- items: Array<DropdownButtonItem | DropdownButtonCustomItem>;
21
- } & WrapperElmProps<'details', 'open' | 'name'> & SSRSupportProps;
27
+ } & Prefix<Omit<ButtonVariantProps, 'small'>, 'button'> & WrapperElmProps<'details', 'open' | 'name'> & SSRSupportProps;
22
28
  export declare const DropdownButton: (props: DropdownButtonProps) => JSX.Element;
23
29
  export {};
@@ -20,7 +20,7 @@ export const DropdownButton = (props) => {
20
20
  middleware: [flip(), shift()],
21
21
  whileElementsMounted: autoUpdate,
22
22
  });
23
- const { wrapperProps = {} } = props;
23
+ const { onItemClick, wrapperProps = {} } = props;
24
24
  return (React.createElement("details", Object.assign({}, wrapperProps, { className: modifiedClass('DropdownButton', isOpen && 'open', wrapperProps.className), open: isOpen, onBlur: (e) => {
25
25
  var _a;
26
26
  if (!isHovering) {
@@ -64,9 +64,15 @@ export const DropdownButton = (props) => {
64
64
  'data-icon': item.icon,
65
65
  'arial-label': item.labelLong,
66
66
  };
67
- return (React.createElement("li", { key: i, className: "DropdownButton__item" }, isBrowser && onClick ? (React.createElement("button", Object.assign({}, commonProps, { type: "button", "aria-controls": item.controlsId, onClick: (e) => {
68
- onClick(item) !== false && closeMenuStat();
69
- } }), label)) : href != null ? (React.createElement("a", Object.assign({}, commonProps, { href: href, hrefLang: item.hrefLang, target: item.target }), label)) : null));
67
+ const doRenderButton = isBrowser && (onClick || (onItemClick && href == null));
68
+ return (React.createElement("li", { key: i, className: modifiedClass('DropdownButton__item', item.modifier), "aria-current": item.current || undefined }, doRenderButton ? (React.createElement("button", Object.assign({}, commonProps, { type: "button", "aria-controls": item.controlsId, onClick: () => {
69
+ const keepOpen1 = onClick && onClick(item) === false;
70
+ const keepOpen2 = onItemClick && onItemClick(item) === false;
71
+ !(keepOpen1 || keepOpen2) && closeMenuStat();
72
+ } }), label)) : href != null ? (React.createElement("a", Object.assign({}, commonProps, { href: href, hrefLang: item.hrefLang, target: item.target, onClick: () => {
73
+ const keepOpen = onItemClick && onItemClick(item) === false;
74
+ !keepOpen && closeMenuStat();
75
+ } }), label)) : null));
70
76
  }),
71
77
  React.createElement(FocusTrap, { Tag: "li", depth: 2 }))));
72
78
  };
package/esm/MainMenu2.js CHANGED
@@ -85,7 +85,8 @@ const getRenderers = (props) => {
85
85
  size: 'small',
86
86
  }
87
87
  : undefined;
88
- return (React.createElement(Tag, { key: key, className: modifiedClass(`${classPrefix}item`, item.modifier), "aria-current": item.current || undefined }, isBrowser && (onClick || (href == null && onItemClick)) ? (React.createElement(ButtonTag, Object.assign({}, commonProps, { type: "button", "aria-controls": controlsId, onClick: () => {
88
+ const doRenderButton = isBrowser && (onClick || (onItemClick && href == null));
89
+ return (React.createElement(Tag, { key: key, className: modifiedClass(`${classPrefix}item`, item.modifier), "aria-current": item.current || undefined }, doRenderButton ? (React.createElement(ButtonTag, Object.assign({}, commonProps, { type: "button", "aria-controls": controlsId, onClick: () => {
89
90
  const keepOpen1 = onClick && onClick(item) === false;
90
91
  const keepOpen2 = onItemClick && onItemClick(item) === false;
91
92
  !(keepOpen1 || keepOpen2) && closeMenu();
@@ -1,3 +1,11 @@
1
1
  // expose `focus-visible` to consumers of `@reykjavik/hanna-react`
2
2
  // without requiring them to install it as a dependency in their project.
3
3
  import '@reykjavik/hanna-utils/focus-visible';
4
+ /** @deprecated This polyfill is not needed anymore (Will be removed in v0.11) */
5
+ if (process.env.NODE_ENV !== 'production') {
6
+ console.warn('Deprecation Warning:\n' +
7
+ 'The `focus-visible` polyfill isn not needed anymore as browser support ' +
8
+ ' is now widespread. You can safely remove all imports of the ' +
9
+ '`@reykjavik/hanna-react/focus-visible` module from your project..\n' +
10
+ '(This module will be removed in v0.11 of `@reykjavik/hanna-react`)');
11
+ }
package/focus-visible.js CHANGED
@@ -3,3 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // expose `focus-visible` to consumers of `@reykjavik/hanna-react`
4
4
  // without requiring them to install it as a dependency in their project.
5
5
  require("@reykjavik/hanna-utils/focus-visible");
6
+ /** @deprecated This polyfill is not needed anymore (Will be removed in v0.11) */
7
+ if (process.env.NODE_ENV !== 'production') {
8
+ console.warn('Deprecation Warning:\n' +
9
+ 'The `focus-visible` polyfill isn not needed anymore as browser support ' +
10
+ ' is now widespread. You can safely remove all imports of the ' +
11
+ '`@reykjavik/hanna-react/focus-visible` module from your project..\n' +
12
+ '(This module will be removed in v0.11 of `@reykjavik/hanna-react`)');
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/hanna-react",
3
- "version": "0.10.140",
3
+ "version": "0.10.142",
4
4
  "author": "Reykjavík (http://www.reykjavik.is)",
5
5
  "contributors": [
6
6
  "Hugsmiðjan ehf (http://www.hugsmidjan.is)",