@scality/core-ui 0.166.0 → 0.167.0

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 (104) hide show
  1. package/.storybook/preview.js +6 -4
  2. package/README.md +27 -80
  3. package/dist/components/barchart/BarChart.component.d.ts +5 -0
  4. package/dist/components/barchart/BarChart.component.d.ts.map +1 -1
  5. package/dist/components/barchart/BarChart.component.js +5 -0
  6. package/dist/components/button/Button.component.d.ts +2 -1
  7. package/dist/components/button/Button.component.d.ts.map +1 -1
  8. package/dist/components/button/Button.component.js +2 -1
  9. package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -1
  10. package/dist/components/chartlegend/ChartLegend.js +7 -13
  11. package/dist/components/chartlegend/ChartLegendWrapper.d.ts +1 -2
  12. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -1
  13. package/dist/components/chartlegend/ChartLegendWrapper.js +4 -9
  14. package/dist/components/icon/Icon.component.d.ts +9 -11
  15. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  16. package/dist/components/icon/Icon.component.js +2 -0
  17. package/dist/components/linetemporalchart/ChartUtil.d.ts +3 -2
  18. package/dist/components/linetemporalchart/ChartUtil.d.ts.map +1 -1
  19. package/dist/components/linetemporalchart/ChartUtil.js +24 -20
  20. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts +4 -0
  21. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts.map +1 -1
  22. package/dist/components/linetemporalchart/LineTemporalChart.component.js +4 -0
  23. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +1 -1
  24. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
  25. package/dist/index.d.ts +1 -11
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +0 -11
  28. package/dist/next.d.ts +1 -0
  29. package/dist/next.d.ts.map +1 -1
  30. package/jest.config.js +1 -0
  31. package/package.json +16 -37
  32. package/src/lib/components/barchart/BarChart.component.tsx +5 -0
  33. package/src/lib/components/button/Button.component.tsx +2 -1
  34. package/src/lib/components/chartlegend/ChartLegend.test.tsx +17 -0
  35. package/src/lib/components/chartlegend/ChartLegend.tsx +6 -12
  36. package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +5 -13
  37. package/src/lib/components/icon/Icon.component.tsx +12 -1
  38. package/src/lib/components/linetemporalchart/ChartUtil.test.ts +23 -35
  39. package/src/lib/components/linetemporalchart/ChartUtil.ts +32 -26
  40. package/src/lib/components/linetemporalchart/LineTemporalChart.component.tsx +19 -15
  41. package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +5 -5
  42. package/src/lib/components/selectv2/selectv2.test.tsx +1 -1
  43. package/src/lib/components/toast/useMutationsHandler.test.tsx +22 -32
  44. package/src/lib/index.ts +6 -11
  45. package/src/lib/next.ts +1 -0
  46. package/stories/barchart.stories.tsx +1 -1
  47. package/stories/card.stories.tsx +7 -5
  48. package/stories/controls.ts +19 -20
  49. package/stories/linecharttemporal.stories.tsx +1 -1
  50. package/stories/linetimeseriechart.stories.tsx +49 -0
  51. package/stories/navbar.stories.tsx +103 -0
  52. package/stories/tabsv2.stories.tsx +51 -56
  53. package/dist/components/areachart/AreaChart.component.d.ts +0 -13
  54. package/dist/components/areachart/AreaChart.component.d.ts.map +0 -1
  55. package/dist/components/areachart/AreaChart.component.js +0 -27
  56. package/dist/components/chips/Chips.component.d.ts +0 -21
  57. package/dist/components/chips/Chips.component.d.ts.map +0 -1
  58. package/dist/components/chips/Chips.component.js +0 -105
  59. package/dist/components/cloudprogressbar/CloudProgressBar.component.d.ts +0 -10
  60. package/dist/components/cloudprogressbar/CloudProgressBar.component.d.ts.map +0 -1
  61. package/dist/components/cloudprogressbar/CloudProgressBar.component.js +0 -38
  62. package/dist/components/collapsiblepanel/CollapsiblePanel.component.d.ts +0 -9
  63. package/dist/components/collapsiblepanel/CollapsiblePanel.component.d.ts.map +0 -1
  64. package/dist/components/collapsiblepanel/CollapsiblePanel.component.js +0 -44
  65. package/dist/components/linechart/LineChart.component.d.ts +0 -21
  66. package/dist/components/linechart/LineChart.component.d.ts.map +0 -1
  67. package/dist/components/linechart/LineChart.component.js +0 -109
  68. package/dist/components/multiselect/MultiSelect.component.d.ts +0 -28
  69. package/dist/components/multiselect/MultiSelect.component.d.ts.map +0 -1
  70. package/dist/components/multiselect/MultiSelect.component.js +0 -73
  71. package/dist/components/select/Select.component.d.ts +0 -14
  72. package/dist/components/select/Select.component.d.ts.map +0 -1
  73. package/dist/components/select/Select.component.js +0 -71
  74. package/dist/components/spacedbox/SpacedBox.d.ts +0 -34
  75. package/dist/components/spacedbox/SpacedBox.d.ts.map +0 -1
  76. package/dist/components/spacedbox/SpacedBox.js +0 -64
  77. package/dist/components/sparkline/SparkLine.component.d.ts +0 -18
  78. package/dist/components/sparkline/SparkLine.component.d.ts.map +0 -1
  79. package/dist/components/sparkline/SparkLine.component.js +0 -148
  80. package/dist/components/vegachart/VegaChart.component.d.ts +0 -13
  81. package/dist/components/vegachart/VegaChart.component.d.ts.map +0 -1
  82. package/dist/components/vegachart/VegaChart.component.js +0 -120
  83. package/plopfile.js +0 -38
  84. package/src/lib/components/areachart/AreaChart.component.tsx +0 -49
  85. package/src/lib/components/chips/Chips.component.tsx +0 -169
  86. package/src/lib/components/cloudprogressbar/CloudProgressBar.component.tsx +0 -105
  87. package/src/lib/components/collapsiblepanel/CollapsiblePanel.component.tsx +0 -77
  88. package/src/lib/components/linechart/LineChart.component.tsx +0 -152
  89. package/src/lib/components/multiselect/MultiSelect.component.tsx +0 -158
  90. package/src/lib/components/select/Select.component.tsx +0 -98
  91. package/src/lib/components/spacedbox/SpacedBox.ts +0 -116
  92. package/src/lib/components/sparkline/SparkLine.component.tsx +0 -176
  93. package/src/lib/components/vegachart/VegaChart.component.tsx +0 -146
  94. package/stories/areachart.stories.tsx +0 -120
  95. package/stories/chips.stories.tsx +0 -107
  96. package/stories/cloudprogressbar.stories.tsx +0 -93
  97. package/stories/collapsiblepanel.stories.tsx +0 -57
  98. package/stories/data/areachart.ts +0 -122
  99. package/stories/data/sparklinechart.ts +0 -164
  100. package/stories/linechart.stories.tsx +0 -319
  101. package/stories/multiselect.stories.tsx +0 -126
  102. package/stories/select.stories.tsx +0 -52
  103. package/stories/sparkline.stories.tsx +0 -85
  104. package/stories/vegachart.stories.tsx +0 -98
@@ -1,105 +0,0 @@
1
- import styled, { css, keyframes } from 'styled-components';
2
- import { coreUIAvailableThemes } from '../../style/theme';
3
- export type CloudProgressBarProps = {
4
- percentage: number;
5
- borderSize: string;
6
- cloudColor?: string;
7
- progressCloudColor?: string;
8
- children: JSX.Element;
9
- };
10
-
11
- const keyFrameCloud = (props) => {
12
- return keyframes`
13
- from {
14
- height:100%
15
- }
16
- to {
17
- height:${100 - props.percentage}%
18
- }`;
19
- };
20
-
21
- const Container = styled.div`
22
- ${(props) => {
23
- return css`
24
- text-align: center;
25
- position: relative;
26
- `;
27
- }}
28
- `;
29
- const ContainerProgress = styled.div<{ percentage: number }>`
30
- ${(props) => {
31
- return css`
32
- animation-duration: 1s;
33
- animation-fill-mode: both;
34
- animation-name: ${keyFrameCloud};
35
- position: absolute;
36
- top: 0;
37
- left: 0;
38
- width: 100%;
39
- overflow: hidden;
40
- `;
41
- }}
42
- `;
43
-
44
- const Cloud = ({ strokeColor, borderSize }) => (
45
- <svg
46
- xmlns="http://www.w3.org/2000/svg"
47
- viewBox="0 15 72 42"
48
- enableBackground="new 0 0 72 72"
49
- >
50
- <g>
51
- <path
52
- fill="none"
53
- stroke={strokeColor}
54
- strokeWidth={borderSize}
55
- strokeLinecap="round"
56
- strokeLinejoin="round"
57
- strokeMiterlimit="10"
58
- d="M15.9,30.3c0,0.4-0.4,0.8-0.8,0.8C10,31.6,6,36.7,6,42.9c0,6.6,4.5,11.9,10.2,11.9h38.7C61,54.8,66,49.1,66,42.2c0-6.6-4.6-12.1-10.4-12.5c-0.4,0-0.8-0.3-0.9-0.8c-1.3-6.7-7.3-11.7-14.3-11.7c-4.6,0-8.7,2.1-11.3,5.4C28.8,23,28.3,23.1,28,23c-1-0.4-2.1-0.6-3.3-0.6C20.1,22.3,16.3,25.8,15.9,30.3z"
59
- />
60
- </g>
61
- </svg>
62
- );
63
-
64
- const CloudProgress = ({ strokeColor, percentage, borderSize }) => (
65
- <ContainerProgress percentage={percentage}>
66
- <svg
67
- xmlns="http://www.w3.org/2000/svg"
68
- viewBox="0 15 72 42"
69
- enableBackground="new 0 0 72 72"
70
- >
71
- <g>
72
- <path
73
- fill="none"
74
- stroke={strokeColor}
75
- strokeWidth={borderSize}
76
- strokeLinecap="round"
77
- strokeLinejoin="round"
78
- strokeMiterlimit="10"
79
- d="M15.9,30.3c0,0.4-0.4,0.8-0.8,0.8C10,31.6,6,36.7,6,42.9c0,6.6,4.5,11.9,10.2,11.9h38.7C61,54.8,66,49.1,66,42.2c0-6.6-4.6-12.1-10.4-12.5c-0.4,0-0.8-0.3-0.9-0.8c-1.3-6.7-7.3-11.7-14.3-11.7c-4.6,0-8.7,2.1-11.3,5.4C28.8,23,28.3,23.1,28,23c-1-0.4-2.1-0.6-3.3-0.6C20.1,22.3,16.3,25.8,15.9,30.3z"
80
- />
81
- </g>
82
- </svg>
83
- </ContainerProgress>
84
- );
85
-
86
- const CloudProgressBar = ({
87
- percentage = 0,
88
- borderSize = '2px',
89
- cloudColor = coreUIAvailableThemes.darkRebrand.statusHealthy,
90
- progressCloudColor = coreUIAvailableThemes.darkRebrand.backgroundLevel1,
91
- children,
92
- }: CloudProgressBarProps) => (
93
- <Container className="sc-cloudprogressbar">
94
- <Cloud strokeColor={progressCloudColor} borderSize={borderSize} />
95
- <CloudProgress
96
- strokeColor={cloudColor}
97
- percentage={percentage}
98
- borderSize={borderSize}
99
- />
100
-
101
- {children}
102
- </Container>
103
- );
104
-
105
- export { CloudProgressBar };
@@ -1,77 +0,0 @@
1
- import styled from 'styled-components';
2
- import { spacing } from '../../spacing';
3
- import { fontSize } from '../../style/theme';
4
- import { Icon } from '../icon/Icon.component';
5
- type Props = {
6
- expanded: boolean;
7
- onHeaderClick: (arg0: any) => void;
8
- children: React.ReactNode;
9
- headerItems: Array<JSX.Element>;
10
- };
11
- const ARROW = {
12
- colapsed: 'fas fa-angle-down',
13
- expanded: 'fas fa-angle-up',
14
- };
15
- const HeaderText = styled.div`
16
- display: flex;
17
- align-items: center;
18
- flex-grow: 1;
19
- `;
20
- const HeaderItem = styled.div`
21
- margin-right: ${spacing.r16};
22
- display: flex;
23
- flex-grow: 1;
24
- `;
25
- const HeaderIcon = styled.div`
26
- font-size: ${fontSize.larger};
27
- margin: 0 ${spacing.r16};
28
- `;
29
- const CollapsiblePanelContainer = styled.div`
30
- display: flex;
31
- flex-direction: column;
32
- border-radius: 4px;
33
- background-color: ${(props) => props.theme.backgroundLevel1};
34
- color: ${(props) => props.theme.textPrimary};
35
- `;
36
- const HeaderContainer = styled.div`
37
- display: flex;
38
- cursor: pointer;
39
- padding: ${spacing.r16};
40
- `;
41
- const ExpandedContainer = styled.div`
42
- padding: ${spacing.r16};
43
- color: ${(props) => props.theme.textPrimary};
44
- background-color: ${(props) => props.theme.backgroundLevel1};
45
- `;
46
-
47
- function CollapsiblePanel({
48
- expanded = false,
49
- onHeaderClick,
50
- children,
51
- headerItems = [],
52
- }: Props) {
53
- return (
54
- <CollapsiblePanelContainer className="sc-collapsiblepanel">
55
- <HeaderContainer
56
- onClick={onHeaderClick}
57
- className="sc-collapsiblepanel-header"
58
- >
59
- <HeaderText>
60
- {headerItems.map((item, index) => (
61
- <HeaderItem key={index}>{item}</HeaderItem>
62
- ))}
63
- </HeaderText>
64
- <HeaderIcon>
65
- <Icon name={expanded ? 'Dropdown-up' : 'Dropdown-down'} />
66
- </HeaderIcon>
67
- </HeaderContainer>
68
- {expanded && (
69
- <ExpandedContainer className="sc-collapsiblepanel-content">
70
- {children}
71
- </ExpandedContainer>
72
- )}
73
- </CollapsiblePanelContainer>
74
- );
75
- }
76
-
77
- export { CollapsiblePanel };
@@ -1,152 +0,0 @@
1
- // @ts-nocheck
2
- import { $PropertyType } from 'utility-types';
3
- import { VegaChart } from '../vegachart/VegaChart.component';
4
- import type { Encoding, Field } from 'vega-lite';
5
- type Props = {
6
- id: string;
7
- data: Array<Record<string, any>>;
8
- xAxis: Record<string, any>;
9
- yAxis: Array<Record<string, any>>;
10
- color?: Record<string, any>;
11
- tooltip?: boolean;
12
- lineConfig?: Record<string, any>;
13
- width?: number;
14
- height?: number;
15
- displayTrendLine?: boolean;
16
- strokeDashEncodingConfig?: $PropertyType<Encoding<Field>, 'strokeDash'>;
17
- opacityEncodingConfig?: $PropertyType<Encoding<Field>, 'opacity'>;
18
- tooltipConfig?: $PropertyType<Encoding<Field>, 'tooltip'>;
19
- tooltipTheme?: 'light' | 'dark' | 'custom';
20
- };
21
-
22
- function LineChart({
23
- id,
24
- data,
25
- xAxis,
26
- yAxis,
27
- color,
28
- tooltip = false,
29
- lineConfig,
30
- height = 300,
31
- width = 1000,
32
- displayTrendLine = false,
33
- strokeDashEncodingConfig,
34
- opacityEncodingConfig,
35
- tooltipConfig,
36
- tooltipTheme,
37
- ...rest
38
- }: Props) {
39
- // hardcode the trendline configuration for tooltip
40
- const trendline = {
41
- mark: 'rule',
42
- selection: {
43
- index: {
44
- type: 'single',
45
- on: 'mousemove',
46
- encodings: ['x'],
47
- nearest: true,
48
- },
49
- },
50
- encoding: {
51
- color: {
52
- condition: {
53
- selection: {
54
- not: 'index',
55
- },
56
- value: 'transparent',
57
- },
58
- },
59
- },
60
- };
61
-
62
- /*
63
- ** strokeDash encoding allows to define a field in data items that defines the line stroke dash property
64
- ** this would allow to get same color lines but having some dashed and some plains
65
- ** https://vega.github.io/vega-lite/docs/line.html#multi-series-line-chart-with-varying-dashes
66
- */
67
-
68
- /*
69
- ** opacity Encoding allows to define rules for each line's opacity
70
- */
71
- const lines = yAxis.map((y) => ({
72
- mark: {
73
- type: 'line',
74
- ...lineConfig,
75
- },
76
- encoding: {
77
- y,
78
- strokeDash: strokeDashEncodingConfig,
79
- opacity: opacityEncodingConfig,
80
- },
81
- }));
82
- const currentTimeTrendline = {
83
- mark: {
84
- type: 'rule',
85
- style: 'ruleCurrentTime',
86
- color: 'white',
87
- opacity: 0.2,
88
- },
89
- encoding: {
90
- x: {
91
- value: width / 2,
92
- },
93
- y: {
94
- value: height,
95
- },
96
- y2: {
97
- value: 0,
98
- },
99
- },
100
- };
101
- const topTrendline = {
102
- mark: {
103
- type: 'rule',
104
- style: 'ruleTop',
105
- color: 'orange',
106
- opacity: 0.2,
107
- },
108
- encoding: {
109
- y: {
110
- aggregate: 'max',
111
- field: 'capacity',
112
- type: 'quantitative',
113
- },
114
- x: {
115
- value: 0,
116
- },
117
- x2: {
118
- value: width,
119
- },
120
- },
121
- };
122
- const spec = {
123
- data: {
124
- values: data,
125
- },
126
- encoding: {
127
- x: xAxis,
128
- color,
129
- // To disable tooltips for a particular single view specification, you can set the "tooltip" property of a mark definition block to null.
130
- tooltip: tooltip ? [xAxis, ...yAxis] : null,
131
- },
132
- height,
133
- width,
134
- layer: [...lines],
135
- ...rest,
136
- };
137
-
138
- if (tooltip) {
139
- spec.layer.push(tooltipConfig || trendline);
140
- }
141
-
142
- if (displayTrendLine) {
143
- spec.layer.push(currentTimeTrendline);
144
- spec.layer.push(topTrendline);
145
- }
146
-
147
- return (
148
- <VegaChart id={id} spec={spec} theme={tooltipTheme || 'light'}></VegaChart>
149
- );
150
- }
151
-
152
- export { LineChart };
@@ -1,158 +0,0 @@
1
- import styled from 'styled-components';
2
- import { spacing } from '../../spacing';
3
- import { fontSize, fontWeight } from '../../style/theme';
4
- import { getThemePropSelector } from '../../utils';
5
- import { Icon } from '../icon/Icon.component';
6
- import { Button } from './../button/Button.component';
7
- import { Checkbox } from './../checkbox/Checkbox.component';
8
- import { Select } from './../select/Select.component';
9
-
10
- export type ItemProps = {
11
- selected?: boolean;
12
- label: string;
13
- description?: string;
14
- onSelect?: (arg0: any, arg1: any) => void;
15
- //on checkbox click
16
- onItemRemove?: (arg0: any, arg1: any) => void;
17
- };
18
- export type OptionProps = {
19
- label: string;
20
- value: string | number;
21
- };
22
- export type SearchProps = {
23
- placeholder?: string;
24
- options: Array<OptionProps>;
25
- //The options displayed in search suggestion
26
- onSelect: (arg0: any) => void;
27
- //on option click
28
- onAdd?: (arg0: any) => void;
29
- selectedOption: any;
30
- };
31
- type MultiSelectProps = {
32
- title?: string;
33
- items: Array<ItemProps>;
34
- search?: SearchProps;
35
- onItemRemove?: (arg0: any, arg1: any) => void; //on item remove button click
36
- };
37
- const MultiSelectContainer = styled.div`
38
- color: ${getThemePropSelector('textPrimary')};
39
- `;
40
- const MultiSelectTitle = styled.h3`
41
- padding: ${spacing.r16} 0;
42
- margin: 0;
43
- font-weight: ${fontWeight.bold};
44
- font-size: ${fontSize.large};
45
- `;
46
- const MultiSelectItemContainer = styled.div`
47
- margin: ${spacing.r4} 0;
48
- padding: ${spacing.r8} 0;
49
- display: flex;
50
- align-items: center;
51
- border-bottom: 1px solid gray;
52
- &:last-child {
53
- border: none;
54
- }
55
- `;
56
- const MultiSelectSearchContainer = styled.div`
57
- display: flex;
58
- align-items: center;
59
- .sc-select-container {
60
- width: 100%;
61
- }
62
- .sc-button {
63
- margin: 0 ${spacing.r8};
64
- }
65
- `;
66
- const MultiSelectItemLeft = styled.div`
67
- .sc-checkbox,
68
- .sc-button {
69
- margin: 0 ${spacing.r8};
70
- }
71
- `;
72
- const MultiSelectItemCenter = styled.div`
73
- display: flex;
74
- flex-grow: 1;
75
- align-items: center;
76
- justify-content: space-between;
77
- `;
78
- const MultiSelectItemRight = styled.div`
79
- padding: 0 ${spacing.r16};
80
- `;
81
- const MultiSelectItemLabel = styled.span`
82
- font-size: ${fontSize.large};
83
- `;
84
- const MultiSelectItemDescription = styled.span``;
85
-
86
- function MultiSelectItem(props: ItemProps) {
87
- const { selected, label, description, onItemRemove, onSelect } = props;
88
- return (
89
- <MultiSelectItemContainer className="sc-multi-select-item">
90
- <MultiSelectItemLeft className="sc-multi-select-item-left">
91
- {typeof selected === 'boolean' && onSelect && (
92
- <Checkbox
93
- checked={selected}
94
- onChange={(event) => onSelect(label, event)}
95
- />
96
- )}
97
- </MultiSelectItemLeft>
98
- <MultiSelectItemCenter className="sc-multi-select-item-center">
99
- <MultiSelectItemLabel className="sc-multi-select-item-label">
100
- {label}
101
- </MultiSelectItemLabel>
102
- {description && (
103
- <MultiSelectItemDescription className="sc-multi-select-item-description">
104
- {description}
105
- </MultiSelectItemDescription>
106
- )}
107
- </MultiSelectItemCenter>
108
- <MultiSelectItemRight className="sc-multi-select-item-right">
109
- {onItemRemove && (
110
- <Button
111
- inverted={true}
112
- variant="buttonDelete"
113
- onClick={(event) => onItemRemove(label, event)}
114
- icon={<Icon name="Delete" />}
115
- />
116
- )}
117
- </MultiSelectItemRight>
118
- </MultiSelectItemContainer>
119
- );
120
- }
121
-
122
- function MultiSelectSearch(props: SearchProps) {
123
- const { selectedOption, onSelect, onAdd, ...rest } = props;
124
- return (
125
- <MultiSelectSearchContainer className="sc-multi-select-list-search">
126
- <Select
127
- // @ts-ignore
128
- onChange={onSelect}
129
- value={selectedOption}
130
- {...rest}
131
- />
132
- {onAdd && <Button onClick={onAdd} icon={<Icon name="Create-add" />} />}
133
- </MultiSelectSearchContainer>
134
- );
135
- }
136
-
137
- function MultiSelectList({
138
- title = '',
139
- items = [],
140
- search,
141
- onItemRemove,
142
- }: MultiSelectProps) {
143
- return (
144
- <MultiSelectContainer className="sc-multi-select-list">
145
- {title && <MultiSelectTitle>{title}</MultiSelectTitle>}
146
- {search && <MultiSelectSearch {...search} />}
147
- {items.map((item, index) => (
148
- <MultiSelectItem
149
- key={`sc-multi-select-item-${index}`}
150
- onItemRemove={onItemRemove}
151
- {...item}
152
- />
153
- ))}
154
- </MultiSelectContainer>
155
- );
156
- }
157
-
158
- export const MultiSelect = MultiSelectList;
@@ -1,98 +0,0 @@
1
- import ReactSelect from 'react-select';
2
- import styled from 'styled-components';
3
-
4
- import { fontSize, fontWeight, gray, zIndex } from '../../style/theme';
5
- import { getThemePropSelector } from '../../utils';
6
- export type Item = {
7
- label: string;
8
- value: string | number;
9
- };
10
- type Items = Array<Item>;
11
- type Props = {
12
- id?: any;
13
- options: Items;
14
- formatOptionLabel?: (arg0: any) => JSX.Element;
15
- };
16
- const SelectContainer = styled.div`
17
- font-size: ${fontSize.base};
18
- .sc-select__control {
19
- background-color: ${getThemePropSelector('backgroundLevel1')};
20
- border-radius: 4px;
21
- border: 1px solid ${getThemePropSelector('border')};
22
- height: auto;
23
-
24
- .sc-select__placeholder,
25
- .sc-select__single-value {
26
- color: ${getThemePropSelector('textSecondary')};
27
- }
28
- &.sc-select__control--is-focused {
29
- border-color: ${getThemePropSelector('selectedActive')};
30
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),
31
- 0 0 0 1px rgba(0, 126, 255, 0.1);
32
- outline: none;
33
- }
34
- .sc-select__indicator {
35
- color: ${getThemePropSelector('textSecondary')};
36
- &.sc-select__dropdown-indicator:hover {
37
- color: ${getThemePropSelector('selectedActive')};
38
- }
39
- &.sc-select__clear-indicator:hover {
40
- color: ${gray};
41
- }
42
- }
43
- .sc-select__multi-value__remove {
44
- border-radius: 0;
45
- color: ${getThemePropSelector('textSecondary')};
46
- background-color: ${getThemePropSelector('backgroundLevel4')};
47
- &:hover {
48
- color: ${gray};
49
- }
50
- }
51
- .sc-select__multi-value__label {
52
- border-radius: 0;
53
- color: ${getThemePropSelector('selectedActive')};
54
- background-color: ${getThemePropSelector('backgroundLevel4')};
55
- vertical-align: initial;
56
- }
57
- }
58
- .sc-select__menu {
59
- background-color: ${getThemePropSelector('backgroundLevel1')};
60
- color: ${getThemePropSelector('textSecondary')};
61
- border: 1px solid ${getThemePropSelector('selectedActive')};
62
- box-sizing: border-box;
63
- overflow: hidden;
64
- z-index: ${zIndex.dropdown};
65
- .sc-select__option {
66
- &.sc-select__option--is-focused {
67
- background-color: ${getThemePropSelector('backgroundLevel1')};
68
- }
69
- &.sc-select__option--is-selected {
70
- background-color: ${getThemePropSelector('backgroundLevel1')};
71
- color: ${getThemePropSelector('selectedActive')};
72
- font-weight: ${fontWeight.bold};
73
- }
74
- }
75
- }
76
- `;
77
-
78
- const defaultFormatOptionLabel = ({ label, ...rest }) => (
79
- <div className="sc-select-option-label" {...rest}>
80
- {label}
81
- </div>
82
- );
83
-
84
- function SelectBox({ options, formatOptionLabel, ...rest }: Props) {
85
- return (
86
- <SelectContainer className="sc-select-container">
87
- <ReactSelect
88
- className="sc-select"
89
- classNamePrefix="sc-select"
90
- options={options}
91
- formatOptionLabel={formatOptionLabel || defaultFormatOptionLabel}
92
- {...rest}
93
- />
94
- </SelectContainer>
95
- );
96
- }
97
-
98
- export const Select = SelectBox;
@@ -1,116 +0,0 @@
1
- import styled from 'styled-components';
2
- import { spacing } from '../../style/theme';
3
- type SpacingValue = 0 | 1 | 2 | 4 | 8 | 12 | 14 | 16 | 20 | 24 | 28 | 32;
4
- export type Props = {
5
- m?: SpacingValue;
6
- mt?: SpacingValue;
7
- mr?: SpacingValue;
8
- mb?: SpacingValue;
9
- ml?: SpacingValue;
10
- mx?: SpacingValue;
11
- my?: SpacingValue;
12
- p?: SpacingValue;
13
- pt?: SpacingValue;
14
- pr?: SpacingValue;
15
- pb?: SpacingValue;
16
- pl?: SpacingValue;
17
- px?: SpacingValue;
18
- py?: SpacingValue;
19
- };
20
- type PropsName =
21
- | 'm'
22
- | 'mt'
23
- | 'mr'
24
- | 'mb'
25
- | 'ml'
26
- | 'mx'
27
- | 'my'
28
- | 'p'
29
- | 'pt'
30
- | 'pr'
31
- | 'pb'
32
- | 'pl'
33
- | 'px'
34
- | 'py';
35
- type CSSField =
36
- | 'margin'
37
- | 'margin-top'
38
- | 'margin-right'
39
- | 'margin-bottom'
40
- | 'margin-left'
41
- | 'padding'
42
- | 'padding-top'
43
- | 'padding-right'
44
- | 'padding-bottom'
45
- | 'padding-left';
46
- const validValue = [0, 1, 2, 4, 8, 12, 14, 16, 20, 24, 28, 32];
47
-
48
- const createSpacingFn =
49
- (propsName: PropsName, spacingFields: Array<CSSField>) => (props: Props) => {
50
- if (!props[propsName] && props[propsName] !== 0) {
51
- return null;
52
- }
53
-
54
- //@ts-ignore -- this is ensured below
55
- let value: SpacingValue = props[propsName];
56
-
57
- if (!validValue.includes(value)) {
58
- console.warn(
59
- `'${propsName}' props should be a number in this list: ` +
60
- '0, 1, 2, 4, 8, 12, 14, 16, 20, 24, 28, 32',
61
- );
62
- return null;
63
- }
64
-
65
- const result = spacingFields
66
- .map((param: CSSField) => `${param}: ${spacing[`sp${value}`]}`)
67
- .join(';');
68
- return result;
69
- };
70
-
71
- const m = createSpacingFn('m', ['margin']);
72
- const mt = createSpacingFn('mt', ['margin-top']);
73
- const mr = createSpacingFn('mr', ['margin-right']);
74
- const mb = createSpacingFn('mb', ['margin-bottom']);
75
- const ml = createSpacingFn('ml', ['margin-left']);
76
- const mx = createSpacingFn('mx', ['margin-left', 'margin-right']);
77
- const my = createSpacingFn('my', ['margin-top', 'margin-bottom']);
78
- const p = createSpacingFn('p', ['padding']);
79
- const pt = createSpacingFn('pt', ['padding-top']);
80
- const pr = createSpacingFn('pr', ['padding-right']);
81
- const pb = createSpacingFn('pb', ['padding-bottom']);
82
- const pl = createSpacingFn('pl', ['padding-left']);
83
- const px = createSpacingFn('px', ['padding-left', 'padding-right']);
84
- const py = createSpacingFn('py', ['padding-top', 'padding-bottom']);
85
-
86
- /**
87
- * @deprecated
88
- * Please use Box with import { Box } from '@scality/core-ui/dist/next';
89
- *
90
- * Most common use cases:
91
- *
92
- * `<SpacedBox m={14}><Component /></SpacedBox>`
93
- *
94
- * `<SpacedBox as={SpanComponent}><Component /></SpacedBox>`
95
- *
96
- * Props : m, mt, mr, mb, ml, mx, my, p, pt, pr, pb, pl, px, py
97
- *
98
- * Values: 0, 1, 2, 4, 8, 12, 14, 16, 20, 24, 28, 32
99
- */
100
- const SpacedBox = styled.div`
101
- ${m};
102
- ${mt};
103
- ${mr};
104
- ${mb};
105
- ${ml};
106
- ${mx};
107
- ${my};
108
- ${p};
109
- ${pt};
110
- ${pr};
111
- ${pb};
112
- ${pl};
113
- ${px};
114
- ${py};
115
- `;
116
- export { SpacedBox };