@spaced-out/ui-design-system 0.0.6 → 0.0.8

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.
@@ -0,0 +1,146 @@
1
+ // @flow strict
2
+
3
+ import * as React from 'react';
4
+
5
+ import {size36, size100} from '../../styles/variables/_size';
6
+ import {spaceMedium} from '../../styles/variables/_space';
7
+ import {classify} from '../../utils/classify';
8
+
9
+ import {TabDropdown} from './TabDropdown.js';
10
+
11
+ import css from './TabList.module.css';
12
+
13
+
14
+ type ClassNames = $ReadOnly<{wrapper?: string}>;
15
+
16
+ export type TabsProps = {
17
+ classNames?: ClassNames,
18
+ onSelect?: ({tabId?: string, label?: string}) => mixed,
19
+ children?: React.Node,
20
+ size?: 'medium',
21
+ selectedTab?: {tabId?: string, label?: string},
22
+ menuWidth?: string,
23
+ };
24
+
25
+ export const TabList = ({
26
+ classNames,
27
+ children,
28
+ size,
29
+ onSelect,
30
+ selectedTab,
31
+ menuWidth,
32
+ }: TabsProps): React.Node => {
33
+ const ref = React.useRef(null);
34
+
35
+ const [containerWidth, setContainerWidth] = React.useState(0);
36
+
37
+ const childrenWithProps = () => {
38
+ const childrenArray = React.Children.toArray(children);
39
+ const totalChildCount = childrenArray.length;
40
+ let tabListWidth = 0;
41
+ const menuOptions = [];
42
+
43
+ let nodes: React.Node[] = [];
44
+ const tabListNodes: React.Node[] = [];
45
+ for (let i = 0; i < totalChildCount; i++) {
46
+ const child = childrenArray[i];
47
+ const {
48
+ width = size100,
49
+ tabId,
50
+ label,
51
+ disabled,
52
+ iconName,
53
+ iconType,
54
+ } = child.props;
55
+ const widthInt = parseInt(width);
56
+ tabListWidth = tabListWidth + widthInt;
57
+
58
+ if (tabListWidth < containerWidth || i === 0) {
59
+ const childOnSelect = (params) => {
60
+ onSelect && onSelect(params); // call the tab level onSelect
61
+ };
62
+ tabListNodes.push(
63
+ React.cloneElement(child, {
64
+ size,
65
+ onSelect: childOnSelect,
66
+ selectedTab,
67
+ }),
68
+ );
69
+ } else {
70
+ menuOptions.push({
71
+ key: tabId,
72
+ label,
73
+ disabled,
74
+ iconLeft: iconName,
75
+ iconLeftType: iconType,
76
+ });
77
+ }
78
+ }
79
+
80
+ const menuOnSelect = ({key, label}) => {
81
+ onSelect && onSelect({tabId: key, label});
82
+ };
83
+ const selectedOption = {
84
+ key: selectedTab?.tabId,
85
+ label: selectedTab?.label || '',
86
+ };
87
+
88
+ const isMenuOptionSelected = (() => {
89
+ for (let i = 0; i < menuOptions.length; i++) {
90
+ if (menuOptions[i].key === selectedTab?.tabId) {
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ })();
96
+
97
+ const tabDropDownNode = menuOptions.length ? (
98
+ <TabDropdown
99
+ size={size}
100
+ onOptionSelect={menuOnSelect}
101
+ props={{
102
+ tab: {
103
+ label: '...',
104
+ tabId: 'tab-dropdown',
105
+ selectedTab: {tabId: isMenuOptionSelected ? 'tab-dropdown' : ''},
106
+ },
107
+ menu: {
108
+ isFluid: false,
109
+ menuDisabled: false,
110
+ options: menuOptions,
111
+ selectedOption,
112
+ width: menuWidth,
113
+ },
114
+ }}
115
+ />
116
+ ) : null;
117
+
118
+ nodes = [...tabListNodes, tabDropDownNode];
119
+ return nodes;
120
+ };
121
+
122
+ React.useLayoutEffect(() => {
123
+ if (ref.current && ref.current.offsetWidth) {
124
+ const availableContainerWidth =
125
+ ref.current.offsetWidth - (parseInt(size36) + parseInt(spaceMedium));
126
+ setContainerWidth(availableContainerWidth);
127
+ }
128
+ }, [ref.current]);
129
+
130
+ return (
131
+ <div
132
+ ref={ref}
133
+ data-testid="Tabs"
134
+ className={classify(
135
+ css.tabsContainer,
136
+ {
137
+ [css.mediumSize]: size === 'medium',
138
+ [css.smallSize]: size === 'small',
139
+ },
140
+ classNames?.wrapper,
141
+ )}
142
+ >
143
+ {containerWidth ? childrenWithProps() : null}
144
+ </div>
145
+ );
146
+ };
@@ -0,0 +1,11 @@
1
+ @value (colorFillPrimary) from '../../styles/variables/_color.css';
2
+ @value (spaceMedium) from '../../styles/variables/_space.css';
3
+
4
+ @value ( sizeFluid) from '../../styles/variables/_size.css';
5
+
6
+ .tabsContainer {
7
+ display: flex;
8
+ flex-direction: row;
9
+ gap: spaceMedium;
10
+ width: sizeFluid;
11
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _TabList = require("./TabList");
7
+ Object.keys(_TabList).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _TabList[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _TabList[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,4 @@
1
+ // @flow strict
2
+
3
+ export type {TabsProps} from './TabList';
4
+ export * from './TabList';
@@ -24,6 +24,8 @@
24
24
 
25
25
  @value size36: 36px;
26
26
 
27
+ @value size38: 38px;
28
+
27
29
  @value size40: 40px;
28
30
 
29
31
  @value size42: 42px;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.sizeFluid = exports.size960 = exports.size8 = exports.size720 = exports.size60 = exports.size580 = exports.size500 = exports.size5 = exports.size480 = exports.size42 = exports.size400 = exports.size40 = exports.size4 = exports.size380 = exports.size36 = exports.size34 = exports.size300 = exports.size30 = exports.size276 = exports.size240 = exports.size24 = exports.size228 = exports.size22 = exports.size20 = exports.size2 = exports.size18 = exports.size160 = exports.size140 = exports.size12 = exports.size110 = exports.size100 = exports.size10 = void 0;
6
+ exports.sizeFluid = exports.size960 = exports.size8 = exports.size720 = exports.size60 = exports.size580 = exports.size500 = exports.size5 = exports.size480 = exports.size42 = exports.size400 = exports.size40 = exports.size4 = exports.size380 = exports.size38 = exports.size36 = exports.size34 = exports.size300 = exports.size30 = exports.size276 = exports.size240 = exports.size24 = exports.size228 = exports.size22 = exports.size20 = exports.size2 = exports.size18 = exports.size160 = exports.size140 = exports.size12 = exports.size110 = exports.size100 = exports.size10 = void 0;
7
7
 
8
8
  const size2 = '2px';
9
9
  exports.size2 = size2;
@@ -31,6 +31,8 @@ const size34 = '34px';
31
31
  exports.size34 = size34;
32
32
  const size36 = '36px';
33
33
  exports.size36 = size36;
34
+ const size38 = '38px';
35
+ exports.size38 = size38;
34
36
  const size40 = '40px';
35
37
  exports.size40 = size40;
36
38
  const size42 = '42px';
@@ -26,6 +26,8 @@ export const size34 = '34px';
26
26
 
27
27
  export const size36 = '36px';
28
28
 
29
+ export const size38 = '38px';
30
+
29
31
  export const size40 = '40px';
30
32
 
31
33
  export const size42 = '42px';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spaced-out/ui-design-system",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "index.js",
5
5
  "description": "Sense UI components library",
6
6
  "author": {