@zendeskgarden/react-theming 8.74.1 → 9.0.0-next.1

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/README.md CHANGED
@@ -52,20 +52,3 @@ import { Notification } from '@zendeskgarden/react-notifications';
52
52
  <Notification>This notification content will render with RTL layout.</Notification>
53
53
  </ThemeProvider>;
54
54
  ```
55
-
56
- The `withTheme` [HOC](https://reactjs.org/docs/higher-order-components.html)
57
- utility allows any component to interact with its `ThemeProvider`.
58
-
59
- ```jsx
60
- import { withTheme } from '@zendeskgarden/react-theming';
61
-
62
- const Div = ({ theme, children }) => (
63
- <div style={{ direction: theme.rtl ? 'rtl' : 'ltr' }}>{children}</div>
64
- );
65
-
66
- const LocalizedComponent = withTheme(Div);
67
-
68
- <ThemeProvider theme={{ ...DEFAULT_THEME, rtl: true }}>
69
- <LocalizedComponent>RTL localizable</LocalizedComponent>
70
- </ThemeProvider>;
71
- ```
package/dist/index.cjs.js CHANGED
@@ -330,13 +330,6 @@ ThemeProvider.defaultProps = {
330
330
  theme: DEFAULT_THEME
331
331
  };
332
332
 
333
- function isRtl() {
334
- let {
335
- theme
336
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
337
- return Boolean(theme && theme.rtl);
338
- }
339
-
340
333
  function retrieveComponentStyles(componentId, props) {
341
334
  const components = props.theme && props.theme.components;
342
335
  if (!components) {
@@ -349,16 +342,23 @@ function retrieveComponentStyles(componentId, props) {
349
342
  return componentStyles;
350
343
  }
351
344
 
352
- function withTheme(WrappedComponent) {
353
- return styledComponents.withTheme(WrappedComponent);
354
- }
355
-
356
- function getDocument() {
357
- let {
358
- theme
359
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
360
- return theme && theme.document || document;
361
- }
345
+ const POSITION_MAP = {
346
+ top: 'bottom',
347
+ 'top-start': 'bottom-left',
348
+ 'top-end': 'bottom-right',
349
+ right: 'left',
350
+ 'right-start': 'left-top',
351
+ 'right-end': 'left-bottom',
352
+ bottom: 'top',
353
+ 'bottom-start': 'top-left',
354
+ 'bottom-end': 'top-right',
355
+ left: 'right',
356
+ 'left-start': 'right-top',
357
+ 'left-end': 'right-bottom'
358
+ };
359
+ const getArrowPosition = placement => {
360
+ return POSITION_MAP[placement];
361
+ };
362
362
 
363
363
  const DEFAULT_SHADE = 600;
364
364
  const adjust = (color, expected, actual) => {
@@ -410,6 +410,61 @@ const getColor = memoize__default.default(function (hue) {
410
410
  transparency
411
411
  }));
412
412
 
413
+ const PLACEMENT_MAP = {
414
+ end: 'right',
415
+ 'end-top': 'right-start',
416
+ 'end-bottom': 'right-end',
417
+ start: 'left',
418
+ 'start-top': 'left-start',
419
+ 'start-bottom': 'left-end'
420
+ };
421
+ const RTL_PLACEMENT_MAP = {
422
+ left: 'right',
423
+ 'left-start': 'right-start',
424
+ 'left-end': 'right-end',
425
+ 'top-start': 'top-end',
426
+ 'top-end': 'top-start',
427
+ right: 'left',
428
+ 'right-start': 'left-start',
429
+ 'right-end': 'left-end',
430
+ 'bottom-start': 'bottom-end',
431
+ 'bottom-end': 'bottom-start'
432
+ };
433
+ const toFloatingPlacement = (placement, theme) => {
434
+ let retVal = PLACEMENT_MAP[placement] || placement;
435
+ if (theme.rtl) {
436
+ retVal = RTL_PLACEMENT_MAP[retVal] || retVal;
437
+ }
438
+ return retVal;
439
+ };
440
+ const SIDE_FALLBACKS_MAP = {
441
+ top: ['top-start', 'top', 'top-end'],
442
+ right: ['right-start', 'right', 'right-end'],
443
+ bottom: ['bottom-start', 'bottom', 'bottom-end'],
444
+ left: ['left-start', 'left', 'left-end']
445
+ };
446
+ const SIDE_OPPOSITE_MAP = {
447
+ top: 'bottom',
448
+ right: 'left',
449
+ bottom: 'top',
450
+ left: 'right'
451
+ };
452
+ const toFallbackPlacements = (primaryPlacement, theme, fallbackPlacements) => {
453
+ if (Array.isArray(fallbackPlacements) && fallbackPlacements.length > 0) {
454
+ return fallbackPlacements.map(fallbackPlacement => toFloatingPlacement(fallbackPlacement, theme));
455
+ }
456
+ const side = primaryPlacement.split('-')[0];
457
+ const sameSideFallbackPlacements = [...SIDE_FALLBACKS_MAP[side]];
458
+ const oppositeSideFallbackPlacements = SIDE_FALLBACKS_MAP[SIDE_OPPOSITE_MAP[side]];
459
+ sameSideFallbackPlacements.splice(sameSideFallbackPlacements.indexOf(primaryPlacement), 1);
460
+ return [...sameSideFallbackPlacements, ...oppositeSideFallbackPlacements];
461
+ };
462
+ const getFloatingPlacements = (theme, placement, fallbackPlacements) => {
463
+ const floatingPlacement = toFloatingPlacement(placement, theme);
464
+ const floatingFallbackPlacements = toFallbackPlacements(floatingPlacement, theme, fallbackPlacements);
465
+ return [floatingPlacement, floatingFallbackPlacements];
466
+ };
467
+
413
468
  const getFocusBoxShadow = _ref => {
414
469
  let {
415
470
  boxShadow,
@@ -447,6 +502,10 @@ function getLineHeight(height, fontSize) {
447
502
  return heightValue / fontSizeValue;
448
503
  }
449
504
 
505
+ const getMenuPosition = placement => {
506
+ return placement.split('-')[0];
507
+ };
508
+
450
509
  const maxWidth = (breakpoints, breakpoint) => {
451
510
  const keys = Object.keys(breakpoints);
452
511
  const index = keys.indexOf(breakpoint) + 1;
@@ -651,20 +710,23 @@ const focusStyles = _ref => {
651
710
 
652
711
  const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
653
712
  const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
713
+ const PLACEMENT = ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
654
714
 
655
715
  exports.ARRAY_ARROW_POSITION = ARROW_POSITION;
656
716
  exports.ARRAY_MENU_POSITION = MENU_POSITION;
657
717
  exports.DEFAULT_THEME = DEFAULT_THEME;
658
718
  exports.PALETTE = PALETTE;
719
+ exports.PLACEMENT = PLACEMENT;
659
720
  exports.SELECTOR_FOCUS_VISIBLE = SELECTOR_FOCUS_VISIBLE;
660
721
  exports.ThemeProvider = ThemeProvider;
661
722
  exports.arrowStyles = arrowStyles;
662
723
  exports.focusStyles = focusStyles;
724
+ exports.getArrowPosition = getArrowPosition;
663
725
  exports.getColor = getColor;
664
- exports.getDocument = getDocument;
726
+ exports.getFloatingPlacements = getFloatingPlacements;
665
727
  exports.getFocusBoxShadow = getFocusBoxShadow;
666
728
  exports.getLineHeight = getLineHeight;
667
- exports.isRtl = isRtl;
729
+ exports.getMenuPosition = getMenuPosition;
668
730
  exports.mediaQuery = mediaQuery;
669
731
  exports.menuStyles = menuStyles;
670
732
  exports.retrieveComponentStyles = retrieveComponentStyles;
@@ -672,4 +734,3 @@ exports.retrieveTheme = retrieveComponentStyles;
672
734
  exports.useDocument = useDocument;
673
735
  exports.useText = useText;
674
736
  exports.useWindow = useWindow;
675
- exports.withTheme = withTheme;
package/dist/index.esm.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React, { useState, useEffect, useRef, useMemo } from 'react';
9
- import { ThemeProvider as ThemeProvider$1, withTheme as withTheme$1, css, keyframes } from 'styled-components';
9
+ import { ThemeProvider as ThemeProvider$1, css, keyframes } from 'styled-components';
10
10
  import { useFocusVisible } from '@zendeskgarden/container-focusvisible';
11
11
  import { getControlledValue } from '@zendeskgarden/container-utilities';
12
12
  import { rgba, darken, lighten, getValueAndUnit, math } from 'polished';
@@ -323,13 +323,6 @@ ThemeProvider.defaultProps = {
323
323
  theme: DEFAULT_THEME
324
324
  };
325
325
 
326
- function isRtl() {
327
- let {
328
- theme
329
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
330
- return Boolean(theme && theme.rtl);
331
- }
332
-
333
326
  function retrieveComponentStyles(componentId, props) {
334
327
  const components = props.theme && props.theme.components;
335
328
  if (!components) {
@@ -342,16 +335,23 @@ function retrieveComponentStyles(componentId, props) {
342
335
  return componentStyles;
343
336
  }
344
337
 
345
- function withTheme(WrappedComponent) {
346
- return withTheme$1(WrappedComponent);
347
- }
348
-
349
- function getDocument() {
350
- let {
351
- theme
352
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
353
- return theme && theme.document || document;
354
- }
338
+ const POSITION_MAP = {
339
+ top: 'bottom',
340
+ 'top-start': 'bottom-left',
341
+ 'top-end': 'bottom-right',
342
+ right: 'left',
343
+ 'right-start': 'left-top',
344
+ 'right-end': 'left-bottom',
345
+ bottom: 'top',
346
+ 'bottom-start': 'top-left',
347
+ 'bottom-end': 'top-right',
348
+ left: 'right',
349
+ 'left-start': 'right-top',
350
+ 'left-end': 'right-bottom'
351
+ };
352
+ const getArrowPosition = placement => {
353
+ return POSITION_MAP[placement];
354
+ };
355
355
 
356
356
  const DEFAULT_SHADE = 600;
357
357
  const adjust = (color, expected, actual) => {
@@ -403,6 +403,61 @@ const getColor = memoize(function (hue) {
403
403
  transparency
404
404
  }));
405
405
 
406
+ const PLACEMENT_MAP = {
407
+ end: 'right',
408
+ 'end-top': 'right-start',
409
+ 'end-bottom': 'right-end',
410
+ start: 'left',
411
+ 'start-top': 'left-start',
412
+ 'start-bottom': 'left-end'
413
+ };
414
+ const RTL_PLACEMENT_MAP = {
415
+ left: 'right',
416
+ 'left-start': 'right-start',
417
+ 'left-end': 'right-end',
418
+ 'top-start': 'top-end',
419
+ 'top-end': 'top-start',
420
+ right: 'left',
421
+ 'right-start': 'left-start',
422
+ 'right-end': 'left-end',
423
+ 'bottom-start': 'bottom-end',
424
+ 'bottom-end': 'bottom-start'
425
+ };
426
+ const toFloatingPlacement = (placement, theme) => {
427
+ let retVal = PLACEMENT_MAP[placement] || placement;
428
+ if (theme.rtl) {
429
+ retVal = RTL_PLACEMENT_MAP[retVal] || retVal;
430
+ }
431
+ return retVal;
432
+ };
433
+ const SIDE_FALLBACKS_MAP = {
434
+ top: ['top-start', 'top', 'top-end'],
435
+ right: ['right-start', 'right', 'right-end'],
436
+ bottom: ['bottom-start', 'bottom', 'bottom-end'],
437
+ left: ['left-start', 'left', 'left-end']
438
+ };
439
+ const SIDE_OPPOSITE_MAP = {
440
+ top: 'bottom',
441
+ right: 'left',
442
+ bottom: 'top',
443
+ left: 'right'
444
+ };
445
+ const toFallbackPlacements = (primaryPlacement, theme, fallbackPlacements) => {
446
+ if (Array.isArray(fallbackPlacements) && fallbackPlacements.length > 0) {
447
+ return fallbackPlacements.map(fallbackPlacement => toFloatingPlacement(fallbackPlacement, theme));
448
+ }
449
+ const side = primaryPlacement.split('-')[0];
450
+ const sameSideFallbackPlacements = [...SIDE_FALLBACKS_MAP[side]];
451
+ const oppositeSideFallbackPlacements = SIDE_FALLBACKS_MAP[SIDE_OPPOSITE_MAP[side]];
452
+ sameSideFallbackPlacements.splice(sameSideFallbackPlacements.indexOf(primaryPlacement), 1);
453
+ return [...sameSideFallbackPlacements, ...oppositeSideFallbackPlacements];
454
+ };
455
+ const getFloatingPlacements = (theme, placement, fallbackPlacements) => {
456
+ const floatingPlacement = toFloatingPlacement(placement, theme);
457
+ const floatingFallbackPlacements = toFallbackPlacements(floatingPlacement, theme, fallbackPlacements);
458
+ return [floatingPlacement, floatingFallbackPlacements];
459
+ };
460
+
406
461
  const getFocusBoxShadow = _ref => {
407
462
  let {
408
463
  boxShadow,
@@ -440,6 +495,10 @@ function getLineHeight(height, fontSize) {
440
495
  return heightValue / fontSizeValue;
441
496
  }
442
497
 
498
+ const getMenuPosition = placement => {
499
+ return placement.split('-')[0];
500
+ };
501
+
443
502
  const maxWidth = (breakpoints, breakpoint) => {
444
503
  const keys = Object.keys(breakpoints);
445
504
  const index = keys.indexOf(breakpoint) + 1;
@@ -644,5 +703,6 @@ const focusStyles = _ref => {
644
703
 
645
704
  const ARROW_POSITION = ['top', 'top-left', 'top-right', 'right', 'right-top', 'right-bottom', 'bottom', 'bottom-left', 'bottom-right', 'left', 'left-top', 'left-bottom'];
646
705
  const MENU_POSITION = ['top', 'right', 'bottom', 'left'];
706
+ const PLACEMENT = ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'end', 'end-top', 'end-bottom', 'start', 'start-top', 'start-bottom'];
647
707
 
648
- export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, DEFAULT_THEME, PALETTE, SELECTOR_FOCUS_VISIBLE, ThemeProvider, arrowStyles, focusStyles, getColor, getDocument, getFocusBoxShadow, getLineHeight, isRtl, mediaQuery, menuStyles, retrieveComponentStyles, retrieveComponentStyles as retrieveTheme, useDocument, useText, useWindow, withTheme };
708
+ export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, DEFAULT_THEME, PALETTE, PLACEMENT, SELECTOR_FOCUS_VISIBLE, ThemeProvider, arrowStyles, focusStyles, getArrowPosition, getColor, getFloatingPlacements, getFocusBoxShadow, getLineHeight, getMenuPosition, mediaQuery, menuStyles, retrieveComponentStyles, retrieveComponentStyles as retrieveTheme, useDocument, useText, useWindow };
@@ -7,15 +7,15 @@
7
7
  export { ThemeProvider } from './elements/ThemeProvider';
8
8
  export { default as DEFAULT_THEME } from './elements/theme';
9
9
  export { default as PALETTE } from './elements/palette';
10
- export { default as isRtl } from './utils/isRtl';
11
10
  export { default as retrieveComponentStyles,
12
11
  /** `retrieveTheme` is a deprecated usage for v7 compatability */
13
12
  default as retrieveTheme } from './utils/retrieveComponentStyles';
14
- export { default as withTheme } from './utils/withTheme';
15
- export { default as getDocument } from './utils/getDocument';
13
+ export { getArrowPosition } from './utils/getArrowPosition';
16
14
  export { getColor } from './utils/getColor';
15
+ export { getFloatingPlacements } from './utils/getFloatingPlacements';
17
16
  export { getFocusBoxShadow } from './utils/getFocusBoxShadow';
18
17
  export { default as getLineHeight } from './utils/getLineHeight';
18
+ export { getMenuPosition } from './utils/getMenuPosition';
19
19
  export { default as mediaQuery } from './utils/mediaQuery';
20
20
  export { default as arrowStyles } from './utils/arrowStyles';
21
21
  export { useDocument } from './utils/useDocument';
@@ -23,4 +23,4 @@ export { useWindow } from './utils/useWindow';
23
23
  export { useText } from './utils/useText';
24
24
  export { default as menuStyles } from './utils/menuStyles';
25
25
  export { focusStyles, SELECTOR_FOCUS_VISIBLE } from './utils/focusStyles';
26
- export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, type IGardenTheme, type IThemeProviderProps, type ArrowPosition as ARROW_POSITION, type MenuPosition as MENU_POSITION } from './types';
26
+ export { ARROW_POSITION as ARRAY_ARROW_POSITION, MENU_POSITION as ARRAY_MENU_POSITION, PLACEMENT, type IGardenTheme, type IThemeProviderProps, type ArrowPosition as ARROW_POSITION, type MenuPosition as MENU_POSITION, type Placement } from './types';
@@ -10,6 +10,8 @@ export declare const ARROW_POSITION: readonly ["top", "top-left", "top-right", "
10
10
  export type ArrowPosition = (typeof ARROW_POSITION)[number];
11
11
  export declare const MENU_POSITION: readonly ["top", "right", "bottom", "left"];
12
12
  export type MenuPosition = (typeof MENU_POSITION)[number];
13
+ export declare const PLACEMENT: readonly ["top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "end", "end-top", "end-bottom", "start", "start-top", "start-bottom"];
14
+ export type Placement = (typeof PLACEMENT)[number];
13
15
  type Hue = Record<number | string, string> | string;
14
16
  export interface IGardenTheme {
15
17
  rtl: boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright Zendesk, Inc.
3
+ *
4
+ * Use of this source code is governed under the Apache License, Version 2.0
5
+ * found at http://www.apache.org/licenses/LICENSE-2.0.
6
+ */
7
+ import { Placement } from '@floating-ui/react-dom';
8
+ import { ArrowPosition } from '../types';
9
+ export declare const POSITION_MAP: Record<Placement, ArrowPosition>;
10
+ /**
11
+ * Convert Floating-UI placement to a valid `arrowStyles` position.
12
+ *
13
+ * @param {string} placement A Floating-UI placement.
14
+ *
15
+ * @returns An `arrowStyles` position.
16
+ */
17
+ export declare const getArrowPosition: (placement: Placement) => ArrowPosition;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright Zendesk, Inc.
3
+ *
4
+ * Use of this source code is governed under the Apache License, Version 2.0
5
+ * found at http://www.apache.org/licenses/LICENSE-2.0.
6
+ */
7
+ import { Placement as FloatingPlacement } from '@floating-ui/react-dom';
8
+ import { IGardenTheme, Placement } from '../types';
9
+ export declare const PLACEMENT_MAP: Record<string, FloatingPlacement>;
10
+ export declare const RTL_PLACEMENT_MAP: Record<string, FloatingPlacement>;
11
+ /**
12
+ * Convert Garden placements to valid placements for Floating-UI.
13
+ *
14
+ * @param {Object} theme Context `theme` object used to determine if layout is right-to-left.
15
+ * @param {string} placement A Garden placement.
16
+ * @param {Array} fallbackPlacements Optional list of Garden fallback placements.
17
+ *
18
+ * @returns A Floating-UI (placement, fallbackPlacements) tuple.
19
+ */
20
+ export declare const getFloatingPlacements: (theme: IGardenTheme, placement: Placement, fallbackPlacements?: Placement[]) => [FloatingPlacement, FloatingPlacement[]];
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright Zendesk, Inc.
3
+ *
4
+ * Use of this source code is governed under the Apache License, Version 2.0
5
+ * found at http://www.apache.org/licenses/LICENSE-2.0.
6
+ */
7
+ import { Placement } from '@floating-ui/react-dom';
8
+ import { MenuPosition } from '../types';
9
+ /**
10
+ * Convert Floating-UI placement to a valid `menuStyles` position.
11
+ *
12
+ * @param {string} placement A Floating-UI placement.
13
+ *
14
+ * @returns A `menuStyles` position.
15
+ */
16
+ export declare const getMenuPosition: (placement: Placement) => MenuPosition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zendeskgarden/react-theming",
3
- "version": "8.74.1",
3
+ "version": "9.0.0-next.1",
4
4
  "description": "Theming utilities and components within the Garden Design System",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Zendesk Garden <garden@zendesk.com>",
@@ -21,6 +21,7 @@
21
21
  "sideEffects": false,
22
22
  "types": "dist/typings/index.d.ts",
23
23
  "dependencies": {
24
+ "@floating-ui/react-dom": "^2.0.0",
24
25
  "@zendeskgarden/container-focusvisible": "^2.0.0",
25
26
  "@zendeskgarden/container-utilities": "^2.0.0",
26
27
  "lodash.memoize": "^4.1.2",
@@ -30,7 +31,7 @@
30
31
  "peerDependencies": {
31
32
  "react": ">=16.8.0",
32
33
  "react-dom": ">=16.8.0",
33
- "styled-components": "^4.2.0 || ^5.0.0"
34
+ "styled-components": "^4.2.0 || ^5.1.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/lodash.memoize": "4.1.9"
@@ -45,5 +46,5 @@
45
46
  "access": "public"
46
47
  },
47
48
  "zendeskgarden:src": "src/index.ts",
48
- "gitHead": "4637bf600631be336574ddb5a31fda8f9bc27de6"
49
+ "gitHead": "a9e4e776bf6ad8860a198fc24f27b2b5cbc83320"
49
50
  }
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
- import { ThemeProps, DefaultTheme } from 'styled-components';
8
- /** @component */
9
- export default function getDocument({ theme }?: Partial<ThemeProps<Partial<DefaultTheme>>>): any;
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
- import { ThemeProps, DefaultTheme } from 'styled-components';
8
- /** @component */
9
- export default function isRtl({ theme }?: Partial<ThemeProps<Partial<DefaultTheme>>>): boolean;
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright Zendesk, Inc.
3
- *
4
- * Use of this source code is governed under the Apache License, Version 2.0
5
- * found at http://www.apache.org/licenses/LICENSE-2.0.
6
- */
7
- /** @component */
8
- export default function withTheme(WrappedComponent: any): any;