@zohodesk/components 1.0.0-temp-262 → 1.0.0-temp-262.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/es/v1/Tab/Tab.js CHANGED
@@ -9,7 +9,7 @@ import FlexItem from '@zohodesk/layout/es/Flex/FlexItem';
9
9
  import Icon from '@zohodesk/icons/es/Icon';
10
10
  import Typography from "../../Typography/Typography";
11
11
  import { useTabsStyle } from "./context";
12
- import { ICON_PLACEMENT_DIRECTION, ICON_PLACEMENT_TEXT_ALIGN, LABEL_STYLE, SIZE, SIZE_TEXT_SIZE, TEXT_TRANSFORM, TEXT_TRUNCATE } from "./constants";
12
+ import { ICON_PLACEMENT_DIRECTION, ICON_PLACEMENT_JUSTIFY, ICON_PLACEMENT_TEXT_ALIGN, LABEL_STYLE, ORIENTATION, SIZE, SIZE_TEXT_SIZE, TEXT_ONLY_TEXT_ALIGN, TEXT_TRANSFORM, TEXT_TRUNCATE } from "./constants";
13
13
  import { Tab_defaultProps } from "./props/defaultProps";
14
14
  import { Tab_propTypes } from "./props/propTypes";
15
15
 
@@ -54,6 +54,7 @@ const Tab = props => {
54
54
  getClasses,
55
55
  iconPlacement,
56
56
  labelStyle,
57
+ orientation,
57
58
  size,
58
59
  hasScroll,
59
60
  hasOverflow,
@@ -66,11 +67,15 @@ const Tab = props => {
66
67
  const isIconMode = labelStyle === LABEL_STYLE.ICON;
67
68
  const hasText = !isIconMode && !!text;
68
69
  const showIcon = !isTextOnly;
70
+ const textAlign = isTextOnly ? TEXT_ONLY_TEXT_ALIGN : ICON_PLACEMENT_TEXT_ALIGN[iconPlacement];
71
+ const hasIconAndText = !isTextOnly && !isIconMode;
72
+ const justifyContent = orientation === ORIENTATION.VERTICAL && hasIconAndText ? ICON_PLACEMENT_JUSTIFY[iconPlacement] : 'center';
69
73
  const resolvedTextSize = SIZE_TEXT_SIZE[size] || SIZE_TEXT_SIZE[SIZE.MEDIUM];
70
74
  const canShrink = !hasOverflow && !hasScroll;
71
75
  const styleOverrides = {
72
76
  labelStyle,
73
77
  canShrink,
78
+ isDisabled,
74
79
  customClass
75
80
  };
76
81
  const accessibleName = ariaLabel || (isIconMode ? text : undefined);
@@ -99,7 +104,7 @@ const Tab = props => {
99
104
  getRef: getRef,
100
105
  displayMode: "inlineFlex",
101
106
  alignItems: "center",
102
- justifyContent: "center"
107
+ justifyContent: justifyContent
103
108
  }, elementProps, {
104
109
  customId: customId,
105
110
  testId: testId,
@@ -121,7 +126,7 @@ const Tab = props => {
121
126
  display: "flex",
122
127
  direction: ICON_PLACEMENT_DIRECTION[iconPlacement],
123
128
  alignItems: "center",
124
- justifyContent: "center",
129
+ justifyContent: justifyContent,
125
130
  customClass: classes.content,
126
131
  customAttributes: contentAttributes
127
132
  }, icon ? /*#__PURE__*/React.createElement(FlexItem, {
@@ -136,7 +141,7 @@ const Tab = props => {
136
141
  $flag_dotted: textTruncate === TEXT_TRUNCATE.ELLIPSIS,
137
142
  $ui_wordBreak: textTruncate === TEXT_TRUNCATE.CLAMP ? 'breakWord' : undefined,
138
143
  $ui_transform: textTransform,
139
- $ui_textAlign: ICON_PLACEMENT_TEXT_ALIGN[iconPlacement],
144
+ $ui_textAlign: textAlign,
140
145
  $ui_className: classes.tabText,
141
146
  $i18n_dataTitle: title || text,
142
147
  $tagAttributes_container: tabTextAttributes
@@ -8,8 +8,8 @@ import Tabs from "../Tabs";
8
8
  import TabList from "../TabList";
9
9
  import Tab from "../Tab";
10
10
  import TabPanel from "../TabPanel";
11
- import { SIZE, VARIANT, POSITION, LABEL_STYLE, ICON_PLACEMENT } from "../constants";
12
- import { INFO_BAR_RAIL, SUBTAB_STRIP } from "../constants/presets";
11
+ import { SIZE, VARIANT, POSITION, LABEL_STYLE, ICON_PLACEMENT, ICON_SPACING } from "../constants";
12
+ import { INFO_BAR_RAIL, INFO_BAR_RAIL_TEXT, INFO_BAR_RAIL_ICON_LEFT, INFO_BAR_RAIL_ICON_TOP, SUBTAB_STRIP } from "../constants/presets";
13
13
  /*
14
14
  * `uniqueId` is passed on every render on purpose. The id scope is otherwise
15
15
  * counter-based, so every id, aria-controls and aria-labelledby recorded below
@@ -33,6 +33,8 @@ const ITEMS = [{
33
33
  text: 'Charlie'
34
34
  }];
35
35
 
36
+ const readStylesheet = () => fs.readFileSync(path.join(__dirname, '..', 'css', 'Tab_v1.module.css'), 'utf8');
37
+
36
38
  function Group({
37
39
  uniqueId = 'tabs',
38
40
  tabProps,
@@ -578,7 +580,7 @@ describe('Tab - Snapshot', () => {
578
580
  expect(baseElement).toMatchSnapshot();
579
581
  });
580
582
  describe('Presets', () => {
581
- const presets = [['INFO_BAR_RAIL', INFO_BAR_RAIL], ['SUBTAB_STRIP', SUBTAB_STRIP]];
583
+ const presets = [['INFO_BAR_RAIL', INFO_BAR_RAIL], ['INFO_BAR_RAIL_TEXT', INFO_BAR_RAIL_TEXT], ['INFO_BAR_RAIL_ICON_LEFT', INFO_BAR_RAIL_ICON_LEFT], ['INFO_BAR_RAIL_ICON_TOP', INFO_BAR_RAIL_ICON_TOP], ['SUBTAB_STRIP', SUBTAB_STRIP]];
582
584
  test.each(presets)('Should render preset %s', (_name, preset) => {
583
585
  const {
584
586
  asFragment
@@ -591,6 +593,155 @@ describe('Tab - Snapshot', () => {
591
593
  });
592
594
  });
593
595
  });
596
+ describe('Tab - Info bar rail presets', () => {
597
+ const railPresets = [INFO_BAR_RAIL, INFO_BAR_RAIL_TEXT, INFO_BAR_RAIL_ICON_LEFT, INFO_BAR_RAIL_ICON_TOP];
598
+ test('every rail preset is the same vertical rail, differing only in its label', () => {
599
+ railPresets.forEach(preset => {
600
+ expect(preset).toMatchObject({
601
+ position: POSITION.LEFT,
602
+ hasSurface: true,
603
+ hasListBorder: true
604
+ });
605
+ });
606
+ });
607
+ test('INFO_BAR_RAIL_TEXT renders the text and drops the icon', () => {
608
+ const {
609
+ container
610
+ } = render( /*#__PURE__*/React.createElement(Group, _extends({}, INFO_BAR_RAIL_TEXT, {
611
+ tabProps: {
612
+ iconName: 'ZD-TB-menu'
613
+ }
614
+ })));
615
+ const tab = container.querySelector('[role="tab"]');
616
+ expect(tab.textContent).toContain('one');
617
+ expect(tab.querySelector('.iconBox')).toBeNull();
618
+ });
619
+ test.each([['INFO_BAR_RAIL_ICON_LEFT', INFO_BAR_RAIL_ICON_LEFT, ICON_PLACEMENT.LEFT], ['INFO_BAR_RAIL_ICON_TOP', INFO_BAR_RAIL_ICON_TOP, ICON_PLACEMENT.TOP]])('%s renders icon and text with its iconPlacement', (_name, preset, placement) => {
620
+ expect(preset.labelStyle).toBe(LABEL_STYLE.ICON_AND_TEXT);
621
+ expect(preset.iconPlacement).toBe(placement);
622
+ const {
623
+ container
624
+ } = render( /*#__PURE__*/React.createElement(Group, _extends({}, preset, {
625
+ tabProps: {
626
+ iconName: 'ZD-TB-menu'
627
+ }
628
+ })));
629
+ const tab = container.querySelector('[role="tab"]');
630
+ expect(tab.textContent).toContain('one');
631
+ expect(tab.querySelector('.iconBox')).not.toBeNull();
632
+ });
633
+
634
+ const getLabelParts = container => {
635
+ const tab = container.querySelector('[role="tab"]');
636
+ const content = tab.firstElementChild;
637
+ const text = Array.from(content.children).find(node => node.textContent === 'one');
638
+ return {
639
+ tab,
640
+ content,
641
+ text
642
+ };
643
+ };
644
+
645
+ test.each([['INFO_BAR_RAIL_ICON_LEFT', INFO_BAR_RAIL_ICON_LEFT]])('%s aligns the label to the start of the rail with left-aligned text', (_name, preset) => {
646
+ const {
647
+ container
648
+ } = render( /*#__PURE__*/React.createElement(Group, _extends({}, preset, {
649
+ tabProps: {
650
+ iconName: 'ZD-TB-menu'
651
+ }
652
+ })));
653
+ const {
654
+ tab,
655
+ content,
656
+ text
657
+ } = getLabelParts(container);
658
+ expect(tab.className).toContain('d-justify-start');
659
+ expect(content.className).toContain('d-justify-start');
660
+ expect(text.className).toContain('textalign_left');
661
+ });
662
+ test.each([['INFO_BAR_RAIL_ICON_TOP', INFO_BAR_RAIL_ICON_TOP], ['INFO_BAR_RAIL_TEXT', INFO_BAR_RAIL_TEXT]])('%s centres the label and its text', (_name, preset) => {
663
+ const {
664
+ container
665
+ } = render( /*#__PURE__*/React.createElement(Group, _extends({}, preset, {
666
+ tabProps: {
667
+ iconName: 'ZD-TB-menu'
668
+ }
669
+ })));
670
+ const {
671
+ tab,
672
+ content,
673
+ text
674
+ } = getLabelParts(container);
675
+ expect(tab.className).toContain('d-justify-center');
676
+ expect(content.className).toContain('d-justify-center');
677
+ expect(text.className).toContain('textalign_center');
678
+ });
679
+ test('a horizontal strip keeps a side-icon label centred in its tab', () => {
680
+ const {
681
+ container
682
+ } = render( /*#__PURE__*/React.createElement(Group, {
683
+ labelStyle: LABEL_STYLE.ICON_AND_TEXT,
684
+ isFullWidth: true,
685
+ tabProps: {
686
+ iconName: 'ZD-TB-menu'
687
+ }
688
+ }));
689
+ const {
690
+ tab,
691
+ content
692
+ } = getLabelParts(container);
693
+ expect(tab.className).toContain('d-justify-center');
694
+ expect(content.className).toContain('d-justify-center');
695
+ });
696
+ test.each(ICON_SPACING)('iconSpacing %s maps to a gap utility that css-utility defines', spacing => {
697
+ const utilities = fs.readFileSync(require.resolve('@dot-system/css-utility/es/utilities.plain.css'), 'utf8');
698
+ const {
699
+ container
700
+ } = render( /*#__PURE__*/React.createElement(Group, _extends({}, INFO_BAR_RAIL_ICON_LEFT, {
701
+ iconSpacing: spacing,
702
+ tabProps: {
703
+ iconName: 'ZD-TB-menu'
704
+ }
705
+ })));
706
+ const content = container.querySelector('[role="tab"]').firstElementChild;
707
+ const gapClass = `d-gap-[${spacing}px]`;
708
+ expect(content.classList.contains(gapClass)).toBe(true);
709
+ expect(utilities).toContain(`.d-gap-\\[${spacing}px\\]`);
710
+ });
711
+ test('SUBTAB_STRIP mirrors the ticket detail-view subtabs (v0 delta tabs)', () => {
712
+ expect(SUBTAB_STRIP).toMatchObject({
713
+ position: POSITION.TOP,
714
+ size: SIZE.SMALL,
715
+ variant: VARIANT.DOTTED,
716
+ labelStyle: LABEL_STYLE.TEXT,
717
+ textTransform: 'upper',
718
+ textTruncate: 'ellipsis',
719
+ hasListBorder: true,
720
+ hasListPadding: true
721
+ });
722
+ const {
723
+ container
724
+ } = render( /*#__PURE__*/React.createElement(Group, SUBTAB_STRIP));
725
+ const list = container.querySelector('[role="tablist"]');
726
+ const tab = container.querySelector('[role="tab"]');
727
+ expect(list.className).toContain('listDotted'); // The strip draws its own bottom border and start inset; a consumer only adjusts them.
728
+
729
+ expect(list.className).toContain('listTop');
730
+ expect(list.className).not.toContain('listNoBorder');
731
+ expect(list.className).not.toContain('listNoPadding');
732
+ expect(tab.className).toContain('tabDotted');
733
+ expect(tab.className).toContain('tabSmall');
734
+ expect(tab.querySelector('.transform_upper')).not.toBeNull();
735
+ });
736
+ test('a rail preset can move to the right edge by overriding position', () => {
737
+ const {
738
+ container
739
+ } = render( /*#__PURE__*/React.createElement(Group, _extends({}, INFO_BAR_RAIL_ICON_TOP, {
740
+ position: POSITION.RIGHT
741
+ })));
742
+ expect(container.querySelector('[role="tablist"]').className).toContain('listRight');
743
+ });
744
+ });
594
745
  /*
595
746
  * The behaviour these cover is not visible in a snapshot: the F1 font-size
596
747
  * cascade fix, the F2 customClass merge fix, a keyboard model, and a click
@@ -598,18 +749,17 @@ describe('Tab - Snapshot', () => {
598
749
  */
599
750
 
600
751
  describe('Tab - Behaviour', () => {
601
- test('size is the sole font-size axis: no variant re-declares --local-tab-font-size', () => {
752
+ test('size is the sole font-size axis: no variant declares font-size', () => {
602
753
  /*
603
- * The F1 regression. `--local-tab-font-size` is set by `.small` / `.medium`
604
- * / `.large`, but the `.elevated` / `.spaced` / `.dotted` preset-variant
605
- * blocks used to redeclare it too - and, appearing later in the file at
606
- * equal specificity on the same <Tabs> root element, they always won, so
607
- * `size` silently had no visible effect whenever a variant was also set.
754
+ * The F1 regression. Size and variant classes sit on the same tab element
755
+ * at equal specificity, and the variant blocks come later in the file - so
756
+ * a variant that declared font-size would always win, and `size` would
757
+ * silently have no visible effect whenever a variant was also set.
608
758
  *
609
759
  * jsdom applies no CSS-module styles, so the guard is in two parts: both
610
- * the size and variant classes must reach the root element together, and
611
- * the stylesheet must declare `--local-tab-font-size` in exactly the size
612
- * blocks, never in the variant blocks.
760
+ * the size and variant classes must reach the tab element together, and
761
+ * the stylesheet must declare font-size in exactly the size blocks, never
762
+ * in the variant blocks.
613
763
  */
614
764
  const {
615
765
  container
@@ -617,22 +767,150 @@ describe('Tab - Behaviour', () => {
617
767
  size: "large",
618
768
  variant: "elevated"
619
769
  }));
620
- const root = container.firstChild;
621
- expect(root.className).toContain('large');
622
- expect(root.className).toContain('elevated');
623
- const css = fs.readFileSync(path.join(__dirname, '..', 'css', 'Tab_v1.module.css'), 'utf8');
770
+ const tab = container.querySelector('[role="tab"]');
771
+ expect(tab.className).toContain('tabLarge');
772
+ expect(tab.className).toContain('tabElevated');
773
+ const css = readStylesheet();
624
774
 
625
775
  const block = selector => {
626
776
  const match = css.match(new RegExp(`\\.${selector}\\s*\\{([^}]*)\\}`));
627
777
  return match ? match[1] : '';
628
778
  };
629
779
 
630
- expect(block('small')).toMatch(/--local-tab-font-size/);
631
- expect(block('medium')).toMatch(/--local-tab-font-size/);
632
- expect(block('large')).toMatch(/--local-tab-font-size/);
633
- expect(block('elevated')).not.toMatch(/--local-tab-font-size/);
634
- expect(block('spaced')).not.toMatch(/--local-tab-font-size/);
635
- expect(block('dotted')).not.toMatch(/--local-tab-font-size/);
780
+ expect(block('tabSmall')).toMatch(/font-size/);
781
+ expect(block('tabMedium')).toMatch(/font-size/);
782
+ expect(block('tabLarge')).toMatch(/font-size/);
783
+ expect(block('tabElevated')).not.toMatch(/font-size/);
784
+ expect(block('tabSpaced')).not.toMatch(/font-size/);
785
+ expect(block('tabDotted')).not.toMatch(/font-size/);
786
+ });
787
+ test('the stylesheet exposes no --local-* variables: customClass is the only override path', () => {
788
+ expect(readStylesheet()).not.toMatch(/--local-/);
789
+ });
790
+ test('modifier classes land on the slots, not on the Tabs root', () => {
791
+ const {
792
+ container
793
+ } = render( /*#__PURE__*/React.createElement(Group, {
794
+ size: "small",
795
+ variant: "dotted",
796
+ position: "left",
797
+ hasSurface: true,
798
+ hasListBorder: false,
799
+ hasListPadding: false
800
+ }));
801
+ const root = container.firstChild;
802
+ const list = container.querySelector('[role="tablist"]');
803
+ const tab = container.querySelector('[role="tab"]');
804
+ const panel = container.querySelector('[role="tabpanel"]');
805
+ expect(root.className).not.toMatch(/\b(small|dotted|left|vertical|hasSurface)\b/);
806
+ expect(list.className).toEqual(expect.stringContaining('listDotted'));
807
+ expect(list.className).toEqual(expect.stringContaining('listLeft'));
808
+ expect(list.className).toEqual(expect.stringContaining('listVertical'));
809
+ expect(list.className).toEqual(expect.stringContaining('listSurface'));
810
+ expect(list.className).toEqual(expect.stringContaining('listNoBorder'));
811
+ expect(list.className).toEqual(expect.stringContaining('listNoPadding'));
812
+ expect(tab.className).toEqual(expect.stringContaining('tabSmall'));
813
+ expect(tab.className).toEqual(expect.stringContaining('tabDotted'));
814
+ expect(tab.className).toEqual(expect.stringContaining('tabLeft'));
815
+ expect(tab.className).toEqual(expect.stringContaining('tabVertical'));
816
+ expect(tab.className).toEqual(expect.stringContaining('tabSurface'));
817
+ expect(panel.className).toEqual(expect.stringContaining('panelSurface'));
818
+ expect(panel.className).toEqual(expect.stringContaining('panelDotted'));
819
+ });
820
+ test('a nested Tabs does not inherit the outer variant', () => {
821
+ render( /*#__PURE__*/React.createElement(Tabs, {
822
+ uniqueId: "outer",
823
+ variant: "elevated"
824
+ }, /*#__PURE__*/React.createElement(TabList, {
825
+ ariaLabel: "Outer"
826
+ }, /*#__PURE__*/React.createElement(Tab, {
827
+ value: "o1",
828
+ text: "o1"
829
+ })), /*#__PURE__*/React.createElement(TabPanel, {
830
+ value: "o1"
831
+ }, /*#__PURE__*/React.createElement(Tabs, {
832
+ uniqueId: "inner",
833
+ variant: "underline"
834
+ }, /*#__PURE__*/React.createElement(TabList, {
835
+ ariaLabel: "Inner"
836
+ }, /*#__PURE__*/React.createElement(Tab, {
837
+ value: "i1",
838
+ text: "i1"
839
+ })), /*#__PURE__*/React.createElement(TabPanel, {
840
+ value: "i1"
841
+ }, "Inner panel")))));
842
+ const outerTab = screen.getByRole('tab', {
843
+ name: 'o1'
844
+ });
845
+ const innerTab = screen.getByRole('tab', {
846
+ name: 'i1'
847
+ });
848
+ expect(outerTab.className).toContain('tabElevated');
849
+ expect(innerTab.className).not.toContain('tabElevated');
850
+ expect(screen.getByRole('tablist', {
851
+ name: 'Inner'
852
+ }).className).not.toContain('listElevated');
853
+ });
854
+ test('single-value properties come from d-* utilities, as mutually exclusive variants', () => {
855
+ /*
856
+ * The utility layer and the component layer have no declared order, so a
857
+ * d-* class must never compete with a component rule for one property.
858
+ * Exclusive values are cva variants: exactly one of each pair is applied.
859
+ */
860
+ render( /*#__PURE__*/React.createElement(Tabs, {
861
+ uniqueId: "tabs",
862
+ variant: "dotted"
863
+ }, /*#__PURE__*/React.createElement(TabList, {
864
+ ariaLabel: "Cities"
865
+ }, /*#__PURE__*/React.createElement(Tab, {
866
+ value: "one",
867
+ text: "one"
868
+ }), /*#__PURE__*/React.createElement(Tab, {
869
+ value: "two",
870
+ text: "two",
871
+ isDisabled: true
872
+ }))));
873
+ const [enabled, disabled] = screen.getAllByRole('tab');
874
+ const list = screen.getByRole('tablist');
875
+ expect(enabled.className).toContain('d-cursor-pointer');
876
+ expect(enabled.className).not.toContain('d-cursor-not-allowed');
877
+ expect(disabled.className).toContain('d-cursor-not-allowed');
878
+ expect(disabled.className).not.toContain('d-cursor-pointer');
879
+ expect(list.className).toContain('d-border-dotted');
880
+ expect(list.className).not.toContain('d-border-solid'); // margins are set per variant in the stylesheet, so no d-m-0 to fight them
881
+
882
+ expect(enabled.className).not.toContain('d-m-0');
883
+ });
884
+ test('the stylesheet does not re-declare what a d-* utility now owns', () => {
885
+ const css = readStylesheet();
886
+
887
+ const block = selector => {
888
+ const match = css.match(new RegExp(`(?:^|\\n)\\.${selector}\\s*\\{([^}]*)\\}`));
889
+ return match ? match[1] : null;
890
+ };
891
+
892
+ expect(block('content')).toBeNull();
893
+ expect(block('tabText')).toBeNull();
894
+ expect(block('moreWrapper')).toBeNull();
895
+ expect(block('moreItem')).toBeNull();
896
+ expect(block('list')).not.toMatch(/border-style/);
897
+ expect(block('tab')).not.toMatch(/cursor/);
898
+ expect(css).not.toMatch(/\.listDotted\s*\{[^}]*border-style/);
899
+ });
900
+ test('a customClass slot class is appended after the component classes', () => {
901
+ const {
902
+ container
903
+ } = render( /*#__PURE__*/React.createElement(Group, {
904
+ variant: "elevated",
905
+ customClass: {
906
+ tab: 'my-tab',
907
+ list: 'my-list'
908
+ }
909
+ }));
910
+ const tab = container.querySelector('[role="tab"]');
911
+ const list = container.querySelector('[role="tablist"]');
912
+ expect(tab.className.trim().split(/\s+/).pop()).toBe('my-tab');
913
+ expect(list.className).toMatch(/listElevated.*my-list/);
636
914
  });
637
915
  test('a group customClass.tab is merged with, not overwritten by, a per-tab getClasses call', () => {
638
916
  /*