@laerdal/life-react-components 1.3.1 → 1.3.2-dev.3
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/dist/esm/Accordion/ContentAccordion.js +238 -0
- package/dist/esm/Accordion/ContentAccordion.js.map +1 -0
- package/dist/esm/Accordion/__tests__/ContetnAccordion.test.js +137 -0
- package/dist/esm/Accordion/__tests__/ContetnAccordion.test.js.map +1 -0
- package/dist/esm/Accordion/index.js +1 -0
- package/dist/esm/Accordion/index.js.map +1 -1
- package/dist/esm/Button/Button.js +8 -53
- package/dist/esm/Button/Button.js.map +1 -1
- package/dist/esm/Modals/__tests__/Modal.test.js +154 -0
- package/dist/esm/Modals/__tests__/Modal.test.js.map +1 -0
- package/dist/esm/Tabs/TabLink.js +1 -0
- package/dist/esm/Tabs/TabLink.js.map +1 -1
- package/dist/js/Accordion/ContentAccordion.d.ts +18 -0
- package/dist/js/Accordion/ContentAccordion.js +151 -0
- package/dist/js/Accordion/ContentAccordion.js.map +1 -0
- package/dist/js/Accordion/__tests__/ContetnAccordion.test.js +151 -0
- package/dist/js/Accordion/__tests__/ContetnAccordion.test.js.map +1 -0
- package/dist/js/Accordion/index.d.ts +1 -0
- package/dist/js/Accordion/index.js +8 -0
- package/dist/js/Accordion/index.js.map +1 -1
- package/dist/js/Button/Button.js +6 -12
- package/dist/js/Button/Button.js.map +1 -1
- package/dist/js/Modals/__tests__/Modal.test.js +231 -0
- package/dist/js/Modals/__tests__/Modal.test.js.map +1 -0
- package/dist/js/Tabs/TabLink.js +1 -1
- package/dist/js/Tabs/TabLink.js.map +1 -1
- package/dist/umd/Accordion/ContentAccordion.js +266 -0
- package/dist/umd/Accordion/ContentAccordion.js.map +1 -0
- package/dist/umd/Accordion/__tests__/ContetnAccordion.test.js +165 -0
- package/dist/umd/Accordion/__tests__/ContetnAccordion.test.js.map +1 -0
- package/dist/umd/Accordion/index.js +10 -4
- package/dist/umd/Accordion/index.js.map +1 -1
- package/dist/umd/Button/Button.js +8 -53
- package/dist/umd/Button/Button.js.map +1 -1
- package/dist/umd/Modals/__tests__/Modal.test.js +173 -0
- package/dist/umd/Modals/__tests__/Modal.test.js.map +1 -0
- package/dist/umd/Tabs/TabLink.js +1 -0
- package/dist/umd/Tabs/TabLink.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import _pt from "prop-types";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { Size } from '../types';
|
|
5
|
+
import { SystemIcons } from '../icons';
|
|
6
|
+
import { ComponentLStyling, ComponentMStyling, ComponentSStyling, ComponentTextStyle } from '../styles/typography';
|
|
7
|
+
import { COLORS } from '../styles';
|
|
8
|
+
import { Z_INDEXES } from '../styles/z-indexes';
|
|
9
|
+
const ContentAccordionWrapper = styled.div`
|
|
10
|
+
width: 100%;
|
|
11
|
+
position: relative;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
.content-accordion-item {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
border-top: 1px solid ${COLORS.neutral_100};
|
|
18
|
+
|
|
19
|
+
.item-header {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
min-height: 48px;
|
|
24
|
+
color: ${COLORS.neutral_600};
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
|
|
27
|
+
&:hover {
|
|
28
|
+
color: ${COLORS.primary_700};
|
|
29
|
+
background-color: ${COLORS.primary_20};
|
|
30
|
+
z-index: ${Z_INDEXES.hover};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:focus {
|
|
34
|
+
box-shadow: 0 4px 12px rgba(46, 127, 161, 0.25), 0 0 8px #2E7FA1;
|
|
35
|
+
background-color: ${COLORS.white};
|
|
36
|
+
z-index: ${Z_INDEXES.focus};
|
|
37
|
+
outline: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&:active {
|
|
41
|
+
color: ${COLORS.primary_800};
|
|
42
|
+
background-color: ${COLORS.primary_100};
|
|
43
|
+
box-shadow: none;
|
|
44
|
+
z-index: ${Z_INDEXES.active};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.item-header-icon,
|
|
48
|
+
.item-header-icon svg {
|
|
49
|
+
width: 24px;
|
|
50
|
+
height: 24px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.item-header-text {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.item-content {
|
|
58
|
+
display: none;
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
|
|
61
|
+
.item-content-header {
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.item-content-body {
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.item-content-footer {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
&.active {
|
|
74
|
+
.item-content {
|
|
75
|
+
display: flex;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&.disabled {
|
|
80
|
+
.item-header {
|
|
81
|
+
color: ${COLORS.neutral_300};
|
|
82
|
+
cursor: not-allowed;
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.content-accordion-item:last-child {
|
|
89
|
+
border-bottom: 1px solid ${COLORS.neutral_100};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&.small {
|
|
93
|
+
min-width: 320px;
|
|
94
|
+
max-width: 528px;
|
|
95
|
+
|
|
96
|
+
.item-header {
|
|
97
|
+
gap: 8px;
|
|
98
|
+
padding: 0 8px;
|
|
99
|
+
${ComponentSStyling(ComponentTextStyle.Regular, null)}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.item-content {
|
|
103
|
+
padding: 0 8px 16px 40px;
|
|
104
|
+
gap: 8px;
|
|
105
|
+
|
|
106
|
+
.item-content-header {
|
|
107
|
+
${ComponentSStyling(ComponentTextStyle.Bold, null)}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.item-content-body {
|
|
111
|
+
${ComponentSStyling(ComponentTextStyle.Regular, null)}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
&.medium {
|
|
118
|
+
min-width: 344px;
|
|
119
|
+
max-width: 584px;
|
|
120
|
+
|
|
121
|
+
.item-header {
|
|
122
|
+
gap: 12px;
|
|
123
|
+
padding: 0 12px;
|
|
124
|
+
${ComponentMStyling(ComponentTextStyle.Regular, null)}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.item-content {
|
|
128
|
+
padding: 8px 12px 24px 48px;
|
|
129
|
+
gap: 12px;
|
|
130
|
+
|
|
131
|
+
.item-content-header {
|
|
132
|
+
${ComponentMStyling(ComponentTextStyle.Bold, null)}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.item-content-body {
|
|
136
|
+
${ComponentMStyling(ComponentTextStyle.Regular, null)}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
&.large {
|
|
143
|
+
min-width: 384px;
|
|
144
|
+
max-width: 656px;
|
|
145
|
+
|
|
146
|
+
.item-header {
|
|
147
|
+
gap: 16px;
|
|
148
|
+
padding: 0 16px;
|
|
149
|
+
${ComponentLStyling(ComponentTextStyle.Regular, null)}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.item-content {
|
|
153
|
+
padding: 16px 16px 32px 56px;
|
|
154
|
+
gap: 16px;
|
|
155
|
+
|
|
156
|
+
.item-content-header {
|
|
157
|
+
${ComponentLStyling(ComponentTextStyle.Bold, null)}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.item-content-body {
|
|
161
|
+
${ComponentLStyling(ComponentTextStyle.Regular, null)}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
export const ContentAccordion = props => {
|
|
167
|
+
const [opened, setOpened] = React.useState([]);
|
|
168
|
+
React.useEffect(() => {
|
|
169
|
+
if (props.multi) {
|
|
170
|
+
setOpened(props.items.filter(item => item.active).map(item => item.key));
|
|
171
|
+
} else {
|
|
172
|
+
let active = props.items.find(item => !!item.active)?.key;
|
|
173
|
+
|
|
174
|
+
if (active) {
|
|
175
|
+
setOpened([active]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}, [props.items, props.multi]);
|
|
179
|
+
|
|
180
|
+
const onItemClick = item => {
|
|
181
|
+
if (item.disabled) return;
|
|
182
|
+
|
|
183
|
+
if (opened.includes(item.key)) {
|
|
184
|
+
setOpened(opened.filter(key => key !== item.key));
|
|
185
|
+
} else {
|
|
186
|
+
if (props.multi) {
|
|
187
|
+
setOpened([...opened, item.key]);
|
|
188
|
+
} else {
|
|
189
|
+
setOpened([item.key]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const renderItem = item => {
|
|
195
|
+
const isActive = opened.includes(item.key);
|
|
196
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
197
|
+
key: item.key,
|
|
198
|
+
id: `item_${item.key}`,
|
|
199
|
+
className: 'content-accordion-item'.concat(isActive ? ' active' : '').concat(item.disabled ? ' disabled' : '')
|
|
200
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
201
|
+
className: 'item-header',
|
|
202
|
+
tabIndex: !item.disabled ? 0 : undefined,
|
|
203
|
+
onMouseDown: e => e.preventDefault(),
|
|
204
|
+
onClick: () => !item.disabled && onItemClick(item),
|
|
205
|
+
onKeyPress: event => event.key === 'Enter' && onItemClick(item)
|
|
206
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
207
|
+
className: 'item-header-icon'
|
|
208
|
+
}, props.multi ? isActive ? /*#__PURE__*/React.createElement(SystemIcons.Minus, null) : /*#__PURE__*/React.createElement(SystemIcons.Plus, null) : isActive ? /*#__PURE__*/React.createElement(SystemIcons.ChevronDown, null) : /*#__PURE__*/React.createElement(SystemIcons.ChevronRight, null)), /*#__PURE__*/React.createElement("div", {
|
|
209
|
+
className: 'item-header-text'
|
|
210
|
+
}, item.title)), /*#__PURE__*/React.createElement("div", {
|
|
211
|
+
className: 'item-content'
|
|
212
|
+
}, item.header && /*#__PURE__*/React.createElement("div", {
|
|
213
|
+
className: 'item-content-header'
|
|
214
|
+
}, item.header), /*#__PURE__*/React.createElement("div", {
|
|
215
|
+
className: 'item-content-body'
|
|
216
|
+
}, item.body), item.footer && /*#__PURE__*/React.createElement("div", {
|
|
217
|
+
className: 'item-content-footer'
|
|
218
|
+
}, item.footer)));
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
return /*#__PURE__*/React.createElement(ContentAccordionWrapper, {
|
|
222
|
+
className: 'content-accordion'.concat(` ${props.size ?? Size.Medium}`)
|
|
223
|
+
}, props.items.map(item => renderItem(item)));
|
|
224
|
+
};
|
|
225
|
+
ContentAccordion.propTypes = {
|
|
226
|
+
items: _pt.arrayOf(_pt.shape({
|
|
227
|
+
key: _pt.string.isRequired,
|
|
228
|
+
title: _pt.string.isRequired,
|
|
229
|
+
header: _pt.string,
|
|
230
|
+
body: _pt.any.isRequired,
|
|
231
|
+
footer: _pt.any,
|
|
232
|
+
disabled: _pt.bool,
|
|
233
|
+
active: _pt.bool
|
|
234
|
+
})).isRequired,
|
|
235
|
+
multi: _pt.bool
|
|
236
|
+
};
|
|
237
|
+
export default ContentAccordion;
|
|
238
|
+
//# sourceMappingURL=ContentAccordion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/Accordion/ContentAccordion.tsx"],"names":["React","styled","Size","SystemIcons","ComponentLStyling","ComponentMStyling","ComponentSStyling","ComponentTextStyle","COLORS","Z_INDEXES","ContentAccordionWrapper","div","neutral_100","neutral_600","primary_700","primary_20","hover","white","focus","primary_800","primary_100","active","neutral_300","Regular","Bold","ContentAccordion","props","opened","setOpened","useState","useEffect","multi","items","filter","item","map","key","find","onItemClick","disabled","includes","renderItem","isActive","concat","undefined","e","preventDefault","event","title","header","body","footer","size","Medium"],"mappings":";AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,MAAP,MAAmB,mBAAnB;AACA,SAAQC,IAAR,QAAmB,UAAnB;AACA,SAAQC,WAAR,QAA0B,UAA1B;AACA,SAAQC,iBAAR,EAA2BC,iBAA3B,EAA8CC,iBAA9C,EAAiEC,kBAAjE,QAA0F,sBAA1F;AACA,SAAQC,MAAR,QAAqB,WAArB;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAGA,MAAMC,uBAAuB,GAAGT,MAAM,CAACU,GAAI;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4BH,MAAM,CAACI,WAAY;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA,eAAeJ,MAAM,CAACK,WAAY;AAClC;AACA;AACA;AACA,iBAAiBL,MAAM,CAACM,WAAY;AACpC,4BAA4BN,MAAM,CAACO,UAAW;AAC9C,mBAAmBN,SAAS,CAACO,KAAM;AACnC;AACA;AACA;AACA;AACA,4BAA4BR,MAAM,CAACS,KAAM;AACzC,mBAAmBR,SAAS,CAACS,KAAM;AACnC;AACA;AACA;AACA;AACA,iBAAiBV,MAAM,CAACW,WAAY;AACpC,4BAA4BX,MAAM,CAACY,WAAY;AAC/C;AACA,mBAAmBX,SAAS,CAACY,MAAO;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiBb,MAAM,CAACc,WAAY;AACpC;AACA;AACA;AACA;AACA;AACA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CAA4B,IAAGjB,KAAK,CAAC0B,IAAN,IAAclD,IAAI,CAACmD,MAAO,EAAzD;AAApC,KACG3B,KAAK,CAACM,KAAN,CAAYG,GAAZ,CAAgBD,IAAI,IAAIO,UAAU,CAACP,IAAD,CAAlC,CADH,CADF;AAKD,CAjFM;;AALLF,EAAAA,K;AAVAI,IAAAA,G;AACAY,IAAAA,K;AACAC,IAAAA,M;AACAC,IAAAA,I;AACAC,IAAAA,M;AACAZ,IAAAA,Q;AACAlB,IAAAA,M;;AAKAU,EAAAA,K;;AAuFF,eAAeN,gBAAf","sourcesContent":["import React from 'react'\nimport styled from 'styled-components';\nimport {Size} from '../types';\nimport {SystemIcons} from '../icons';\nimport {ComponentLStyling, ComponentMStyling, ComponentSStyling, ComponentTextStyle} from '../styles/typography';\nimport {COLORS} from '../styles';\nimport {Z_INDEXES} from '../styles/z-indexes';\n\n\nconst ContentAccordionWrapper = styled.div`\n width: 100%;\n position: relative;\n\n\n .content-accordion-item {\n display: flex;\n flex-direction: column;\n border-top: 1px solid ${COLORS.neutral_100};\n\n .item-header {\n display: flex;\n align-items: center;\n box-sizing: border-box;\n min-height: 48px;\n color: ${COLORS.neutral_600};\n cursor: pointer;\n\n &:hover {\n color: ${COLORS.primary_700};\n background-color: ${COLORS.primary_20};\n z-index: ${Z_INDEXES.hover};\n }\n\n &:focus {\n box-shadow: 0 4px 12px rgba(46, 127, 161, 0.25), 0 0 8px #2E7FA1;\n background-color: ${COLORS.white};\n z-index: ${Z_INDEXES.focus};\n outline: none;\n }\n\n &:active {\n color: ${COLORS.primary_800};\n background-color: ${COLORS.primary_100};\n box-shadow: none;\n z-index: ${Z_INDEXES.active};\n }\n\n .item-header-icon,\n .item-header-icon svg {\n width: 24px;\n height: 24px;\n }\n\n .item-header-text {\n }\n }\n\n .item-content {\n display: none;\n flex-direction: column;\n\n .item-content-header {\n\n }\n\n .item-content-body {\n\n }\n\n .item-content-footer {\n }\n }\n\n &.active {\n .item-content {\n display: flex;\n }\n }\n\n &.disabled {\n .item-header {\n color: ${COLORS.neutral_300};\n cursor: not-allowed;\n pointer-events: none;\n }\n }\n }\n\n .content-accordion-item:last-child {\n border-bottom: 1px solid ${COLORS.neutral_100};\n }\n\n &.small {\n min-width: 320px;\n max-width: 528px;\n\n .item-header {\n gap: 8px;\n padding: 0 8px;\n ${ComponentSStyling(ComponentTextStyle.Regular, null)}\n }\n\n .item-content {\n padding: 0 8px 16px 40px;\n gap: 8px;\n\n .item-content-header {\n ${ComponentSStyling(ComponentTextStyle.Bold, null)}\n }\n\n .item-content-body {\n ${ComponentSStyling(ComponentTextStyle.Regular, null)}\n }\n }\n }\n\n\n &.medium {\n min-width: 344px;\n max-width: 584px;\n\n .item-header {\n gap: 12px;\n padding: 0 12px;\n ${ComponentMStyling(ComponentTextStyle.Regular, null)}\n }\n\n .item-content {\n padding: 8px 12px 24px 48px;\n gap: 12px;\n\n .item-content-header {\n ${ComponentMStyling(ComponentTextStyle.Bold, null)}\n }\n\n .item-content-body {\n ${ComponentMStyling(ComponentTextStyle.Regular, null)}\n }\n\n }\n }\n\n &.large {\n min-width: 384px;\n max-width: 656px;\n\n .item-header {\n gap: 16px;\n padding: 0 16px;\n ${ComponentLStyling(ComponentTextStyle.Regular, null)}\n }\n\n .item-content {\n padding: 16px 16px 32px 56px;\n gap: 16px;\n\n .item-content-header {\n ${ComponentLStyling(ComponentTextStyle.Bold, null)}\n }\n\n .item-content-body {\n ${ComponentLStyling(ComponentTextStyle.Regular, null)}\n }\n }\n }\n`;\n\nexport interface ContentAccordionItem {\n key: string;\n title: string;\n header?: string;\n body: any;\n footer?: any;\n disabled?: boolean;\n active?: boolean;\n}\n\nexport interface ContentAccordionProps {\n items: ContentAccordionItem[];\n multi?: boolean;\n size?: Size;\n}\n\nexport const ContentAccordion: React.FunctionComponent<ContentAccordionProps> = (props) => {\n\n const [opened, setOpened] = React.useState<string[]>([]);\n\n React.useEffect(() => {\n if (props.multi) {\n setOpened(props.items.filter(item => item.active).map(item => item.key));\n } else {\n let active = props.items.find(item => !!item.active)?.key;\n if (active) {\n setOpened([active]);\n }\n }\n }, [props.items, props.multi]);\n\n const onItemClick = (item: ContentAccordionItem) => {\n if (item.disabled) return;\n if (opened.includes(item.key)) {\n setOpened(opened.filter(key => key !== item.key));\n } else {\n if (props.multi) {\n setOpened([...opened, item.key]);\n } else {\n setOpened([item.key]);\n }\n }\n }\n\n const renderItem = (item: ContentAccordionItem) => {\n const isActive = opened.includes(item.key);\n\n return (\n <div key={item.key}\n id={`item_${item.key}`}\n className={'content-accordion-item'.concat(isActive ? ' active' : '').concat(item.disabled ? ' disabled' : '')}>\n <div className={'item-header'}\n tabIndex={!item.disabled ? 0 : undefined}\n onMouseDown={e => e.preventDefault()}\n onClick={() => !item.disabled && onItemClick(item)}\n onKeyPress={event => event.key === 'Enter' && onItemClick(item)}>\n <div className={'item-header-icon'}>\n {\n props.multi\n ? isActive\n ? <SystemIcons.Minus/>\n : <SystemIcons.Plus/>\n : isActive\n ? <SystemIcons.ChevronDown/>\n : <SystemIcons.ChevronRight/>\n }\n </div>\n <div className={'item-header-text'}>\n {item.title}\n </div>\n </div>\n <div className={'item-content'}>\n {\n item.header &&\n <div className={'item-content-header'}>\n {item.header}\n </div>\n }\n <div className={'item-content-body'}>\n {item.body}\n </div>\n {\n item.footer &&\n <div className={'item-content-footer'}>\n {item.footer}\n </div>\n }\n </div>\n </div>\n );\n }\n\n return (\n <ContentAccordionWrapper className={'content-accordion'.concat(` ${props.size ?? Size.Medium}`)}>\n {props.items.map(item => renderItem(item))}\n </ContentAccordionWrapper>\n );\n};\n\nexport default ContentAccordion;\n"],"file":"ContentAccordion.js"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ContentAccordion from '../ContentAccordion';
|
|
3
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
4
|
+
import { Size } from '../../types';
|
|
5
|
+
describe('ContentAccordion', () => {
|
|
6
|
+
const contentAccordionItemsWithBody = [{
|
|
7
|
+
key: '1',
|
|
8
|
+
title: 'Item 1',
|
|
9
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
|
|
10
|
+
}, {
|
|
11
|
+
key: '2',
|
|
12
|
+
title: 'Item 2',
|
|
13
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
14
|
+
active: true
|
|
15
|
+
}, {
|
|
16
|
+
key: '3',
|
|
17
|
+
title: 'Item 3',
|
|
18
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
19
|
+
disabled: true
|
|
20
|
+
}, {
|
|
21
|
+
key: '4',
|
|
22
|
+
title: 'Item 4',
|
|
23
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
|
|
24
|
+
}];
|
|
25
|
+
const contentAccordionItemsWithBodyAndHeaderAndFooter = [{
|
|
26
|
+
key: '1',
|
|
27
|
+
title: 'Item 1',
|
|
28
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
29
|
+
header: 'Header 1',
|
|
30
|
+
footer: /*#__PURE__*/React.createElement("span", null)
|
|
31
|
+
}, {
|
|
32
|
+
key: '2',
|
|
33
|
+
title: 'Item 2',
|
|
34
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
35
|
+
header: 'Header 2',
|
|
36
|
+
footer: /*#__PURE__*/React.createElement("span", null)
|
|
37
|
+
}, {
|
|
38
|
+
key: '3',
|
|
39
|
+
title: 'Item 3',
|
|
40
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
41
|
+
header: 'Header 3',
|
|
42
|
+
footer: /*#__PURE__*/React.createElement("span", null),
|
|
43
|
+
disabled: true
|
|
44
|
+
}, {
|
|
45
|
+
key: '4',
|
|
46
|
+
title: 'Item 4',
|
|
47
|
+
body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
|
48
|
+
header: 'Header 4',
|
|
49
|
+
footer: /*#__PURE__*/React.createElement("span", null)
|
|
50
|
+
}];
|
|
51
|
+
it('should render items in correct state', () => {
|
|
52
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
53
|
+
items: contentAccordionItemsWithBody
|
|
54
|
+
}));
|
|
55
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item').length).toBe(4);
|
|
56
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item disabled').length).toBe(1);
|
|
57
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item disabled')[0].id).toBe('item_3');
|
|
58
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(1);
|
|
59
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_2');
|
|
60
|
+
});
|
|
61
|
+
it('should not render header if not provided', () => {
|
|
62
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
63
|
+
items: contentAccordionItemsWithBody
|
|
64
|
+
}));
|
|
65
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-body').length).toBe(4);
|
|
66
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-header').length).toBe(0);
|
|
67
|
+
});
|
|
68
|
+
it('should not render footer if not provided', () => {
|
|
69
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
70
|
+
items: contentAccordionItemsWithBody
|
|
71
|
+
}));
|
|
72
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-body').length).toBe(4);
|
|
73
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-footer').length).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
it('should render body, header, and footer if all are provided', () => {
|
|
76
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
77
|
+
items: contentAccordionItemsWithBodyAndHeaderAndFooter
|
|
78
|
+
}));
|
|
79
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item').length).toBe(4);
|
|
80
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-body').length).toBe(4);
|
|
81
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-header').length).toBe(4);
|
|
82
|
+
expect(wrapper.baseElement.getElementsByClassName('item-content-footer').length).toBe(4);
|
|
83
|
+
});
|
|
84
|
+
it('should set correct size class name for small accordion', () => {
|
|
85
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
86
|
+
items: contentAccordionItemsWithBodyAndHeaderAndFooter,
|
|
87
|
+
size: Size.Small
|
|
88
|
+
}));
|
|
89
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion small').length).toBe(1);
|
|
90
|
+
});
|
|
91
|
+
it('should set correct size class name for medium accordion', () => {
|
|
92
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
93
|
+
items: contentAccordionItemsWithBodyAndHeaderAndFooter,
|
|
94
|
+
size: Size.Medium
|
|
95
|
+
}));
|
|
96
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion medium').length).toBe(1);
|
|
97
|
+
});
|
|
98
|
+
it('should set correct size class name for large accordion', () => {
|
|
99
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
100
|
+
items: contentAccordionItemsWithBodyAndHeaderAndFooter,
|
|
101
|
+
size: Size.Large
|
|
102
|
+
}));
|
|
103
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion large').length).toBe(1);
|
|
104
|
+
});
|
|
105
|
+
it('should change active state when item header is clicked', () => {
|
|
106
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
107
|
+
items: contentAccordionItemsWithBody,
|
|
108
|
+
multi: false
|
|
109
|
+
}));
|
|
110
|
+
const itemHeader = wrapper.baseElement.getElementsByClassName('item-header')[3];
|
|
111
|
+
fireEvent.click(itemHeader);
|
|
112
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(1);
|
|
113
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_4');
|
|
114
|
+
});
|
|
115
|
+
it('should not change active state when disabled item header is clicked', () => {
|
|
116
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
117
|
+
items: contentAccordionItemsWithBody,
|
|
118
|
+
multi: false
|
|
119
|
+
}));
|
|
120
|
+
const itemHeader = wrapper.baseElement.getElementsByClassName('item-header')[2];
|
|
121
|
+
fireEvent.click(itemHeader);
|
|
122
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(1);
|
|
123
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_2');
|
|
124
|
+
});
|
|
125
|
+
it('should append active items if multi property is true', () => {
|
|
126
|
+
const wrapper = render( /*#__PURE__*/React.createElement(ContentAccordion, {
|
|
127
|
+
items: contentAccordionItemsWithBody,
|
|
128
|
+
multi: true
|
|
129
|
+
}));
|
|
130
|
+
const itemHeader = wrapper.baseElement.getElementsByClassName('item-header')[3];
|
|
131
|
+
fireEvent.click(itemHeader);
|
|
132
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(2);
|
|
133
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_2');
|
|
134
|
+
expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[1].id).toBe('item_4');
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=ContetnAccordion.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/Accordion/__tests__/ContetnAccordion.test.tsx"],"names":["React","ContentAccordion","fireEvent","render","Size","describe","contentAccordionItemsWithBody","key","title","body","active","disabled","contentAccordionItemsWithBodyAndHeaderAndFooter","header","footer","it","wrapper","expect","baseElement","getElementsByClassName","length","toBe","id","Small","Medium","Large","itemHeader","click"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,gBAAP,MAA6B,qBAA7B;AACA,SAAQC,SAAR,EAAmBC,MAAnB,QAAgC,wBAAhC;AACA,SAAQC,IAAR,QAAmB,aAAnB;AAEAC,QAAQ,CAAC,kBAAD,EAAqB,MAAM;AACjC,QAAMC,6BAA6B,GAAG,CACpC;AACEC,IAAAA,GAAG,EAAE,GADP;AAEEC,IAAAA,KAAK,EAAE,QAFT;AAGEC,IAAAA,IAAI,EAAE;AAHR,GADoC,EAMpC;AACEF,IAAAA,GAAG,EAAE,GADP;AAEEC,IAAAA,KAAK,EAAE,QAFT;AAGEC,IAAAA,IAAI,EAAE,6HAHR;AAIEC,IAAAA,MAAM,EAAE;AAJV,GANoC,EAYpC;AACEH,IAAAA,GAAG,EAAE,GADP;AAEEC,IAAAA,KAAK,EAAE,QAFT;AAGEC,IAAAA,IAAI,EAAE,6HAHR;AAIEE,IAAAA,QAAQ,EAAE;AAJZ,GAZoC,EAkBpC;AACEJ,IAAAA,GAAG,EAAE,GADP;AAEEC,IAAAA,KAAK,EAAE,QAFT;AAGEC,IAAAA,IAAI,EAAE;AAHR,GAlBoC,CAAtC;AAyBA,QAAMG,+CAA+C,GAAG,CACtD;AACEL,IAAAA,GAAG,EAAE,GADP;AAEEC,IAAAA,KAAK,EAAE,QAFT;AAGEC,IAAAA,IAAI,EAAE,6HAHR;AAIEI,IAAAA,MAAM,EAAE,UAJV;AAKEC,IAAAA,MAAM,eAAE;AALV,GADsD,EAQtD;AACEP,IAAAA,GAAG,EAAE,GADP;AA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hG;AACAJ,IAAAA,MAAM,CAACD,OAAO,CAACE,WAAR,CAAoBC,sBAApB,CAA2C,+BAA3C,EAA4E,CAA5E,EAA+EG,EAAhF,CAAN,CAA0FD,IAA1F,CAA+F,QAA/F;AACD,GARC,CAAF;AAUAN,EAAAA,EAAE,CAAC,sDAAD,EAAyD,MAAM;AAC/D,UAAMC,OAAO,GAAGb,MAAM,eAAC,oBAAC,gBAAD;AAAkB,MAAA,KAAK,EAAEG,6BAAzB;AAAwD,MAAA,KAAK,EAAE;AAA/D,MAAD,CAAtB;AACA,UAAMoB,UAAU,GAAGV,OAAO,CAACE,WAAR,CAAoBC,sBAApB,CAA2C,aAA3C,EAA0D,CAA1D,CAAnB;AAEAjB,IAAAA,SAAS,CAACyB,KAAV,CAAgBD,UAAhB;AAEAT,IAAAA,MAAM,CAACD,OAAO,CAACE,WAAR,CAAoBC,sBAApB,CAA2C,+BAA3C,EAA4EC,MAA7E,CAAN,CAA2FC,IAA3F,CAAgG,CAAhG;AACAJ,IAAAA,MAAM,CAACD,OAAO,CAACE,WAAR,CAAoBC,sBAApB,CAA2C,+BAA3C,EAA4E,CAA5E,EAA+EG,EAAhF,CAAN,CAA0FD,IAA1F,CAA+F,QAA/F;AACAJ,IAAAA,MAAM,CAACD,OAAO,CAACE,WAAR,CAAoBC,sBAApB,CAA2C,+BAA3C,EAA4E,CAA5E,EAA+EG,EAAhF,CAAN,CAA0FD,IAA1F,CAA+F,QAA/F;AACD,GATC,CAAF;AAWD,CA5IO,CAAR","sourcesContent":["import React from 'react';\nimport ContentAccordion from '../ContentAccordion';\nimport {fireEvent, render} from '@testing-library/react';\nimport {Size} from '../../types';\n\ndescribe('ContentAccordion', () => {\n const contentAccordionItemsWithBody = [\n {\n key: '1',\n title: 'Item 1',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'\n },\n {\n key: '2',\n title: 'Item 2',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n active: true\n },\n {\n key: '3',\n title: 'Item 3',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n disabled: true\n },\n {\n key: '4',\n title: 'Item 4',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'\n }\n ];\n\n const contentAccordionItemsWithBodyAndHeaderAndFooter = [\n {\n key: '1',\n title: 'Item 1',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n header: 'Header 1',\n footer: <span/>,\n },\n {\n key: '2',\n title: 'Item 2',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n header: 'Header 2',\n footer: <span/>,\n },\n {\n key: '3',\n title: 'Item 3',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n header: 'Header 3',\n footer: <span/>,\n disabled: true\n },\n {\n key: '4',\n title: 'Item 4',\n body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',\n header: 'Header 4',\n footer: <span/>,\n }\n ];\n\n it('should render items in correct state', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody}/>);\n\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item').length).toBe(4);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item disabled').length).toBe(1);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item disabled')[0].id).toBe('item_3');\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(1);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_2');\n });\n\n it('should not render header if not provided', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody}/>);\n\n expect(wrapper.baseElement.getElementsByClassName('item-content-body').length).toBe(4);\n expect(wrapper.baseElement.getElementsByClassName('item-content-header').length).toBe(0);\n });\n\n it('should not render footer if not provided', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody}/>);\n\n expect(wrapper.baseElement.getElementsByClassName('item-content-body').length).toBe(4);\n expect(wrapper.baseElement.getElementsByClassName('item-content-footer').length).toBe(0);\n });\n\n it('should render body, header, and footer if all are provided', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}/>);\n\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item').length).toBe(4);\n expect(wrapper.baseElement.getElementsByClassName('item-content-body').length).toBe(4);\n expect(wrapper.baseElement.getElementsByClassName('item-content-header').length).toBe(4);\n expect(wrapper.baseElement.getElementsByClassName('item-content-footer').length).toBe(4);\n });\n\n it('should set correct size class name for small accordion', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}\n size={Size.Small}/>);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion small').length).toBe(1);\n });\n\n it('should set correct size class name for medium accordion', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}\n size={Size.Medium}/>);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion medium').length).toBe(1);\n });\n\n it('should set correct size class name for large accordion', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}\n size={Size.Large}/>);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion large').length).toBe(1);\n });\n\n it('should change active state when item header is clicked', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody} multi={false}/>);\n const itemHeader = wrapper.baseElement.getElementsByClassName('item-header')[3];\n\n fireEvent.click(itemHeader);\n\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(1);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_4');\n });\n\n it('should not change active state when disabled item header is clicked', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody} multi={false}/>);\n const itemHeader = wrapper.baseElement.getElementsByClassName('item-header')[2];\n\n fireEvent.click(itemHeader);\n\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(1);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_2');\n });\n\n it('should append active items if multi property is true', () => {\n const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody} multi={true}/>);\n const itemHeader = wrapper.baseElement.getElementsByClassName('item-header')[3];\n\n fireEvent.click(itemHeader);\n\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active').length).toBe(2);\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[0].id).toBe('item_2');\n expect(wrapper.baseElement.getElementsByClassName('content-accordion-item active')[1].id).toBe('item_4');\n });\n\n});\n"],"file":"ContetnAccordion.test.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Accordion/index.ts"],"names":["default","AccordionMenu","AccordionMenuItem","AccordionMenuWrapper"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/Accordion/index.ts"],"names":["default","AccordionMenu","AccordionMenuItem","ContentAccordion","AccordionMenuWrapper"],"mappings":"AAAA,SAAQA,OAAO,IAAIC,aAAnB,QAAuC,iBAAvC;AACA,SAAQD,OAAO,IAAIE,iBAAnB,QAA2C,iBAA3C;AACA,SAAQC,gBAAR,QAA+B,oBAA/B;AACA,SAAQC,oBAAR,QAAmC,UAAnC","sourcesContent":["export {default as AccordionMenu} from './AccordionMenu';\nexport {default as AccordionMenuItem} from './AccordionMenu';\nexport {ContentAccordion} from './ContentAccordion';\nexport {AccordionMenuWrapper} from './styles';\n"],"file":"index.js"}
|
|
@@ -171,16 +171,10 @@ const Primary = styled.button`
|
|
|
171
171
|
}
|
|
172
172
|
&:disabled > div.button-content,
|
|
173
173
|
&.disabled-state > div.button-content {
|
|
174
|
+
pointer-events: none;
|
|
174
175
|
background-color: ${props => props.colorTheme === 'dark' ? COLORS.primary_700 : COLORS.neutral_100};
|
|
175
176
|
color: ${props => props.colorTheme === 'dark' ? COLORS.primary_800 : COLORS.neutral_300};
|
|
176
177
|
border-color: ${props => props.colorTheme === 'dark' ? COLORS.primary_700 : COLORS.neutral_100};
|
|
177
|
-
cursor: not-allowed;
|
|
178
|
-
&:hover,
|
|
179
|
-
&:active {
|
|
180
|
-
background-color: ${props => props.colorTheme === 'dark' ? COLORS.primary_700 : COLORS.neutral_100};
|
|
181
|
-
color: ${props => props.colorTheme === 'dark' ? COLORS.primary_800 : COLORS.neutral_300};
|
|
182
|
-
border-color: ${props => props.colorTheme === 'dark' ? COLORS.primary_700 : COLORS.neutral_100};
|
|
183
|
-
}
|
|
184
178
|
}
|
|
185
179
|
`;
|
|
186
180
|
const Secondary = styled(Primary)`
|
|
@@ -196,9 +190,9 @@ const Secondary = styled(Primary)`
|
|
|
196
190
|
&:focus:not(:focus-visible),
|
|
197
191
|
&:focus:not(:focus-visible) > div.button-content {
|
|
198
192
|
outline: none !important;
|
|
199
|
-
background-color: white;
|
|
200
193
|
}
|
|
201
194
|
|
|
195
|
+
|
|
202
196
|
&:hover > div.button-content,
|
|
203
197
|
&.hover-state > div.button-content {
|
|
204
198
|
color: ${props => props.colorTheme === 'teal' ? COLORS.accent1_700 : props?.colorTheme === 'dark' ? COLORS.primary_200 : COLORS.primary_700};
|
|
@@ -214,7 +208,6 @@ const Secondary = styled(Primary)`
|
|
|
214
208
|
}
|
|
215
209
|
&:active > div.button-content,
|
|
216
210
|
&.active-state > div.button-content {
|
|
217
|
-
background-color: white;
|
|
218
211
|
color: ${props => props.colorTheme === 'teal' ? COLORS.accent1_800 : props?.colorTheme === 'dark' ? COLORS.primary_300 : COLORS.primary_800};
|
|
219
212
|
border-color: ${props => props.colorTheme === 'teal' ? COLORS.accent1_800 : props?.colorTheme === 'dark' ? COLORS.primary_300 : COLORS.primary_800};
|
|
220
213
|
background-color: transparent;
|
|
@@ -226,21 +219,18 @@ const Secondary = styled(Primary)`
|
|
|
226
219
|
}
|
|
227
220
|
}
|
|
228
221
|
}
|
|
229
|
-
|
|
230
|
-
&.disabled-state {
|
|
231
|
-
cursor: not-allowed;
|
|
232
|
-
}
|
|
222
|
+
|
|
233
223
|
&:disabled > div.button-content,
|
|
234
224
|
&.disabled-state > div.button-content {
|
|
235
225
|
background-color: transparent;
|
|
236
226
|
color: ${props => props?.colorTheme === 'dark' ? COLORS.primary_700 : COLORS.neutral_300};
|
|
237
227
|
border-color: ${props => props?.colorTheme === 'dark' ? COLORS.primary_700 : COLORS.neutral_100};
|
|
238
|
-
cursor: not-allowed;
|
|
239
228
|
}
|
|
240
229
|
${props => props.tabbedHere ? tabbedHereStyle('secondary', props.colorTheme) : ''}
|
|
230
|
+
|
|
231
|
+
&:focus,
|
|
241
232
|
&.focus-state {
|
|
242
233
|
${props => tabbedHereStyle('secondary', props?.colorTheme)};
|
|
243
|
-
|
|
244
234
|
}
|
|
245
235
|
`;
|
|
246
236
|
const Tertiary = styled(Primary)`
|
|
@@ -279,27 +269,12 @@ const Tertiary = styled(Primary)`
|
|
|
279
269
|
}
|
|
280
270
|
}
|
|
281
271
|
}
|
|
282
|
-
|
|
283
|
-
&.disabled-state {
|
|
284
|
-
cursor: not-allowed;
|
|
285
|
-
}
|
|
286
|
-
&:disabled > div.button-content,
|
|
287
|
-
&.disabled-state > div.button-content {
|
|
288
|
-
background-color: white !important;
|
|
289
|
-
color: ${COLORS.neutral_300};
|
|
290
|
-
border-color: transparent;
|
|
291
|
-
cursor: not-allowed;
|
|
292
|
-
}
|
|
293
|
-
&:disabled,
|
|
294
|
-
&.disabled-state {
|
|
295
|
-
cursor: not-allowed;
|
|
296
|
-
}
|
|
272
|
+
|
|
297
273
|
&:disabled > div.button-content,
|
|
298
274
|
&.disabled-state > div.button-content {
|
|
299
275
|
background-color: white !important;
|
|
300
276
|
color: ${COLORS.neutral_300};
|
|
301
277
|
border-color: transparent !important;
|
|
302
|
-
cursor: not-allowed;
|
|
303
278
|
}
|
|
304
279
|
${props => props.tabbedHere ? tabbedHereStyle('tertiary', props.colorTheme) : ''}
|
|
305
280
|
&.focus-state {
|
|
@@ -327,22 +302,12 @@ const Correct = styled(Primary)`
|
|
|
327
302
|
border-color: ${COLORS.correct_800};
|
|
328
303
|
background-color: ${COLORS.correct_800};
|
|
329
304
|
}
|
|
330
|
-
|
|
331
|
-
&.disabled-state {
|
|
332
|
-
cursor: not-allowed;
|
|
333
|
-
}
|
|
305
|
+
|
|
334
306
|
&:disabled > div.button-content,
|
|
335
307
|
&.disabled-state > div.button-content {
|
|
336
308
|
background-color: ${COLORS.neutral_100};
|
|
337
309
|
color: ${COLORS.neutral_300};
|
|
338
310
|
border-color: ${COLORS.neutral_100};
|
|
339
|
-
cursor: not-allowed;
|
|
340
|
-
&:hover,
|
|
341
|
-
&:active {
|
|
342
|
-
background-color: ${COLORS.neutral_100};
|
|
343
|
-
color: ${COLORS.neutral_300};
|
|
344
|
-
border-color: ${COLORS.neutral_100};
|
|
345
|
-
}
|
|
346
311
|
}
|
|
347
312
|
`;
|
|
348
313
|
const Critical = styled(Primary)`
|
|
@@ -366,22 +331,12 @@ const Critical = styled(Primary)`
|
|
|
366
331
|
border-color: ${COLORS.critical_800};
|
|
367
332
|
background-color: ${COLORS.critical_800};
|
|
368
333
|
}
|
|
369
|
-
|
|
370
|
-
&.disabled-state {
|
|
371
|
-
cursor: not-allowed;
|
|
372
|
-
}
|
|
334
|
+
|
|
373
335
|
&:disabled > div.button-content,
|
|
374
336
|
&.disabled-state > div.button-content {
|
|
375
337
|
background-color: ${COLORS.neutral_100};
|
|
376
338
|
color: ${COLORS.neutral_300};
|
|
377
339
|
border-color: ${COLORS.neutral_100};
|
|
378
|
-
cursor: not-allowed;
|
|
379
|
-
&:hover,
|
|
380
|
-
&:active {
|
|
381
|
-
background-color: ${COLORS.neutral_100};
|
|
382
|
-
color: ${COLORS.neutral_300};
|
|
383
|
-
border-color: ${COLORS.neutral_100};
|
|
384
|
-
}
|
|
385
340
|
}
|
|
386
341
|
`;
|
|
387
342
|
|