@thecb/components 4.2.8 → 4.3.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/.tool-versions CHANGED
@@ -1 +1 @@
1
- nodejs 10.15.3
1
+ nodejs 15.5.1
package/dist/index.cjs.js CHANGED
@@ -6471,7 +6471,7 @@ var Center = function Center(_ref) {
6471
6471
  };
6472
6472
 
6473
6473
  function _templateObject2$2() {
6474
- var data = _taggedTemplateLiteral(["\n box-sizing: border-box;\n display: flex;\n flex-wrap: ", ";\n justify-content: ", ";\n align-items: ", ";\n margin: calc(", " / 2 * -1);\n min-height: ", ";\n min-width: ", ";\n\n > * {\n margin: calc(", " / 2);\n }\n"]);
6474
+ var data = _taggedTemplateLiteral(["\n box-sizing: border-box;\n display: flex;\n flex-wrap: ", ";\n justify-content: ", ";\n align-items: ", ";\n margin: calc(", " / 2 * -1);\n min-height: ", ";\n min-width: ", ";\n > * {\n margin: calc(", " / 2);\n }\n"]);
6475
6475
 
6476
6476
  _templateObject2$2 = function _templateObject2() {
6477
6477
  return data;
@@ -34466,6 +34466,12 @@ const set$2 = fieldName => value => ({
34466
34466
  const CLEAR = "form/CLEAR";
34467
34467
  const clear = () => ({ type: CLEAR });
34468
34468
 
34469
+ const ADD_VALIDATOR = "field/ADD_VALIDATOR";
34470
+ const addValidator = fieldName => validator => ({
34471
+ type: ADD_VALIDATOR,
34472
+ payload: { fieldName, validator }
34473
+ });
34474
+
34469
34475
  const createFormReducer = formConfig => (
34470
34476
  state = createInitialState(formConfig),
34471
34477
  action
@@ -34497,6 +34503,23 @@ const createFormReducer = formConfig => (
34497
34503
  });
34498
34504
  case CLEAR:
34499
34505
  return createInitialState(formConfig);
34506
+ case ADD_VALIDATOR:
34507
+ const fieldWithOverride = action.payload.fieldName;
34508
+ const newValidator = action.payload.validator;
34509
+
34510
+ return produce(state, draftState => {
34511
+ draftState[fieldWithOverride].validators.push(newValidator);
34512
+ const fields = Object.entries(draftState);
34513
+ for (let entry of fields) {
34514
+ let fieldName = entry[0];
34515
+ let field = entry[1];
34516
+ let errors = computeErrors(fieldName, draftState);
34517
+ let dirty = field.dirty;
34518
+ draftState[fieldName].errors = errors;
34519
+ draftState[fieldName].dirty = dirty;
34520
+ draftState[fieldName].hasErrors = errors.length > 0;
34521
+ }
34522
+ });
34500
34523
  default:
34501
34524
  return state;
34502
34525
  }
@@ -34515,7 +34538,8 @@ const createMapDispatchToProps = formConfig => {
34515
34538
  const keys = Object.keys(formConfig);
34516
34539
  for (let fieldName of keys) {
34517
34540
  dispatchObj.fields[fieldName] = {
34518
- set: value => dispatch(set$2(fieldName)(value))
34541
+ set: value => dispatch(set$2(fieldName)(value)),
34542
+ addValidator: validator => dispatch(addValidator(fieldName)(validator))
34519
34543
  };
34520
34544
  }
34521
34545
  dispatchObj.form = { clear: () => dispatch(clear()) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "4.2.8",
3
+ "version": "4.3.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -80,6 +80,6 @@
80
80
  "ramda": "^0.27.0",
81
81
  "react-aria-modal": "^4.0.0",
82
82
  "react-pose": "^4.0.10",
83
- "redux-freeform": "^5.0.0"
83
+ "redux-freeform": "^5.0.1"
84
84
  }
85
85
  }
@@ -22,7 +22,6 @@ export const ClusterInnerWrapper = styled.div`
22
22
  margin: calc(${({ childGap }) => childGap} / 2 * -1);
23
23
  min-height: ${({ minHeight }) => minHeight};
24
24
  min-width: ${({ minWidth }) => minWidth};
25
-
26
25
  > * {
27
26
  margin: calc(${({ childGap }) => childGap} / 2);
28
27
  }
@@ -0,0 +1,32 @@
1
+ import React from "react";
2
+ import Text from "../text";
3
+ import { WHITE, GRECIAN_GREY } from "../../../constants/colors";
4
+ import { Box } from "../../atoms/layouts";
5
+
6
+ const Tab = ({ label, activeTab, setActiveTab }) => {
7
+ const onClick = () => {
8
+ setActiveTab(label);
9
+ };
10
+
11
+ let className = "tab-list-item";
12
+ if (activeTab === label) {
13
+ className += " tab-list-active";
14
+ }
15
+
16
+ return (
17
+ <Box
18
+ className={className}
19
+ onClick={onClick}
20
+ margin="0 0 -1px 0"
21
+ padding="0.5rem 0.75rem"
22
+ background={activeTab === label ? WHITE : GRECIAN_GREY}
23
+ extraStyles={`cursor: pointer; flex-grow: 1; text-align: center; ${
24
+ activeTab === label ? `list-style: none;` : ``
25
+ }`}
26
+ >
27
+ <Text>{label}</Text>
28
+ </Box>
29
+ );
30
+ };
31
+
32
+ export default Tab;
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+
3
+ import Tab from "./Tab";
4
+ import page from "../../../../.storybook/page";
5
+
6
+ export const tab = () => (
7
+ <Tab label={"Test"} onClick={() => console.log("test")} />
8
+ );
9
+
10
+ const story = page({
11
+ title: "Components|Atoms/Tab",
12
+ Component: Tab
13
+ });
14
+
15
+ export default story;
@@ -0,0 +1,26 @@
1
+ const fontFamily = {
2
+ p: "Public Sans",
3
+ pL: "Public Sans",
4
+ pS: "Public Sans",
5
+ pXS: "Public Sans",
6
+ pXXS: "Public Sans",
7
+ pXL: "Public Sans"
8
+ };
9
+
10
+ // Text uses the same variants as paragraph
11
+ // Use a Paragraph if you want a block level element
12
+ // Use a Text if you want an inline element
13
+
14
+ const fontSize = {
15
+ p: "1rem",
16
+ pL: "1.125rem",
17
+ pS: "0.875rem",
18
+ pXS: "0.75rem",
19
+ pXXS: "0.65rem",
20
+ pXL: "1.5rem"
21
+ };
22
+
23
+ export const fallbackValues = {
24
+ fontFamily,
25
+ fontSize
26
+ };
@@ -0,0 +1,3 @@
1
+ import Tab from "./Tab";
2
+
3
+ export default Tab;
@@ -0,0 +1,59 @@
1
+ import React, { useState } from "react";
2
+ import { Stack, Box, Cluster } from "../../atoms/layouts";
3
+ import { themeComponent } from "../../../util/themeUtils";
4
+ import { fallbackValues } from "./Tabs.theme";
5
+ import Tab from "../../atoms/tab";
6
+
7
+ const HORIZONTAL = "horizontal";
8
+
9
+ const Tabs = ({
10
+ tabsConfig,
11
+ tabsDisplayMode // can be either HORIZONTAL or VERTICAL
12
+ }) => {
13
+ const [activeTab, toggleActiveTab] = useState(tabsConfig.tabs[0].label);
14
+
15
+ const createTabs = (tabConfig, activeTab) => {
16
+ return tabConfig.tabs.map(tab => {
17
+ return (
18
+ <Tab
19
+ activeTab={activeTab}
20
+ key={tab.label}
21
+ label={tab.label}
22
+ setActiveTab={() => toggleActiveTab(tab.label)}
23
+ />
24
+ );
25
+ });
26
+ };
27
+
28
+ const showHorozontal = (tabsConfig, activeTab) => {
29
+ return (
30
+ <Cluster justify={"space-around"}>
31
+ {createTabs(tabsConfig, activeTab)}
32
+ </Cluster>
33
+ );
34
+ };
35
+
36
+ const showVertical = (tabsConfig, activeTab) => {
37
+ return <Stack>{createTabs(tabsConfig, activeTab)}</Stack>;
38
+ };
39
+
40
+ return (
41
+ <Box className="tabs">
42
+ <Box className="tab-list">
43
+ {tabsDisplayMode == HORIZONTAL
44
+ ? showHorozontal(tabsConfig, activeTab)
45
+ : showVertical(tabsConfig, activeTab)}
46
+ </Box>
47
+ <Box className="tab-content">
48
+ <Box>
49
+ {tabsConfig.tabs.map(tab => {
50
+ if (tab.label !== activeTab) return undefined;
51
+ return tab.content;
52
+ })}
53
+ </Box>
54
+ </Box>
55
+ </Box>
56
+ );
57
+ };
58
+
59
+ export default themeComponent(Tabs, "NavigationTab", fallbackValues);
@@ -0,0 +1,241 @@
1
+ import React from "react";
2
+ import { createStore } from "redux";
3
+ import Tabs from "./Tabs";
4
+
5
+ import page from "../../../../.storybook/page";
6
+ import Text from "../../atoms/text";
7
+
8
+ import { createFormState, onlyIntegers, required } from "redux-freeform";
9
+ import DisplayBox from "../../atoms/display-box";
10
+ import { Box } from "../../atoms/layouts";
11
+
12
+ // Including commented out configs as a preliminary work for
13
+ // https://citybase.atlassian.net/browse/KCORE-2973
14
+ // https://citybase.atlassian.net/browse/KCORE-2974
15
+ // https://citybase.atlassian.net/browse/KCORE-2975
16
+
17
+ const ButtonTest = () => (
18
+ <DisplayBox>
19
+ <Text>Test Button Clicks</Text>
20
+ <Box>
21
+ <button onClick={() => console.log("BUTTON TEST;")}>Click me</button>
22
+ </Box>
23
+ </DisplayBox>
24
+ );
25
+
26
+ //const creditCardFormConfig = {
27
+ // amount: {
28
+ // defaultValue: "100.00",
29
+ // validators: [required()]
30
+ // }
31
+ //};
32
+
33
+ const checkFormConfig = {
34
+ amount: {
35
+ defaultValue: "100.00",
36
+ validators: [required()]
37
+ },
38
+ name: {
39
+ validators: [required()]
40
+ },
41
+ accountNumber: {
42
+ validators: [onlyIntegers()]
43
+ },
44
+ routingNumber: {
45
+ validators: [onlyIntegers()]
46
+ },
47
+ checkType: {
48
+ defaultValue: "Personal"
49
+ }
50
+ };
51
+
52
+ //const cashFormConfig = {
53
+ // amount: {
54
+ // defaultValue: "100.00",
55
+ // validators: [required()]
56
+ // }
57
+ //};
58
+ //
59
+ //const MyCreditCardForm = ({ actions, fields }) => {
60
+ // return (
61
+ // <div>
62
+ // {fields.amount.hasErrors && fields.amount.errors.includes(required.error)
63
+ // ? "Amount"
64
+ // : "Amount"}
65
+ // <input
66
+ // value={fields.amount.rawValue}
67
+ // onChange={evt => actions.fields.amount.set(evt.target.value)}
68
+ // type="text"
69
+ // />
70
+ // </div>
71
+ // );
72
+ //};
73
+
74
+ const MyCheckForm = ({ actions, fields }) => (
75
+ <div>
76
+ {fields.amount.hasErrors && fields.amount.errors.includes(required.error)
77
+ ? "AmountError"
78
+ : "Amount"}
79
+ <input
80
+ value={fields.amount.rawValue}
81
+ onChange={evt => actions.fields.amount.set(evt.target.value)}
82
+ type="text"
83
+ />
84
+ {fields.name.hasErrors && fields.name.errors.includes(required.error)
85
+ ? "Name Error"
86
+ : "Name"}
87
+ <input
88
+ value={fields.name.rawValue}
89
+ onChange={evt => actions.fields.name.set(evt.target.value)}
90
+ type="text"
91
+ />
92
+ {fields.accountNumber.hasErrors &&
93
+ fields.accountNumber.errors.includes(required.error)
94
+ ? "Account Number Error"
95
+ : "Account Number"}
96
+ <input
97
+ value={fields.accountNumber.rawValue}
98
+ onChange={evt => actions.fields.accountNumber.set(evt.target.value)}
99
+ type="text"
100
+ />
101
+ {fields.routingNumber.hasErrors &&
102
+ fields.routingNumber.errors.includes(required.error)
103
+ ? "Routing Number Error"
104
+ : "Routing Number"}
105
+ <input
106
+ value={fields.routingNumber.rawValue}
107
+ onChange={evt => actions.fields.routingNumber.set(evt.target.value)}
108
+ type="text"
109
+ />
110
+ {fields.checkType.hasErrors &&
111
+ fields.checkType.errors.includes(required.error)
112
+ ? "Check Type Error"
113
+ : "Check Type"}
114
+ <input
115
+ value={fields.checkType.rawValue}
116
+ onChange={evt => actions.fields.checkType.set(evt.target.value)}
117
+ type="text"
118
+ />
119
+ </div>
120
+ );
121
+
122
+ //const MyCashForm = ({ actions, fields }) => (
123
+ // <div>
124
+ // {fields.amount.hasErrors && fields.amount.errors.includes(required.error)
125
+ // ? "Amount Error"
126
+ // : "Amount"}
127
+ // <input
128
+ // value={fields.amount.rawValue}
129
+ // onChange={evt => actions.fields.amount.set(evt.target.value)}
130
+ // type="text"
131
+ // />
132
+ // </div>
133
+ //);
134
+
135
+ //const {
136
+ // reducer: cardReducer,
137
+ // mapStateToProps: cardMapStateToProps,
138
+ // mapDispatchToProps: cardMapDispatchToProps
139
+ //} = createFormState(creditCardFormConfig);
140
+
141
+ const {
142
+ reducer: checkReducer,
143
+ mapStateToProps: checkMapStateToProps,
144
+ mapDispatchToProps: checkMapDispatchToProps
145
+ } = createFormState(checkFormConfig);
146
+
147
+ //const {
148
+ // reducer: cashReducer,
149
+ // mapStateToProps: cashMapStateToProps,
150
+ // mapDispatchToProps: cashMapDispatchToProps
151
+ //} = createFormState(cashFormConfig);
152
+
153
+ //const cardStore = createStore(
154
+ // cardReducer,
155
+ // window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
156
+ //);
157
+
158
+ const checkStore = createStore(
159
+ checkReducer,
160
+ window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
161
+ );
162
+
163
+ //const cashStore = createStore(
164
+ // cashReducer,
165
+ // window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
166
+ //);
167
+
168
+ //const tabsConfig = {
169
+ // tabs: [
170
+ // {
171
+ // label: 'Credit Card',
172
+ // active: true,
173
+ // content: MyCreditCardForm(
174
+ // {...cardMapStateToProps(cardStore.getState())},
175
+ // {...cardMapDispatchToProps(cardStore.dispatch)}
176
+ // )
177
+ // },
178
+ // {
179
+ // label: 'Check',
180
+ // active: true,
181
+ // content: MyCheckForm(
182
+ // {...checkMapStateToProps(checkStore.getState())},
183
+ // {...checkMapDispatchToProps(checkStore.dispatch)}
184
+ // )
185
+ // },
186
+ // {
187
+ // true: 'Cash',
188
+ // active: true,
189
+ // content: MyCashForm(
190
+ // {...cashMapStateToProps(cashStore.getState())},
191
+ // {...cashMapDispatchToProps(cashStore.dispatch)}
192
+ // )
193
+ // }
194
+ // ]
195
+ //};
196
+
197
+ const LOREM = `
198
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit,
199
+ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
200
+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
201
+ nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
202
+ reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
203
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
204
+ deserunt mollit anim id est laborum.
205
+ `;
206
+
207
+ const tabsConfig = {
208
+ tabs: [
209
+ {
210
+ label: "Credit Card",
211
+ active: true,
212
+ content: <Text>{LOREM}</Text>
213
+ },
214
+ {
215
+ label: "Check",
216
+ active: true,
217
+ content: MyCheckForm(
218
+ { ...checkMapStateToProps(checkStore.getState()) },
219
+ { ...checkMapDispatchToProps(checkStore.dispatch) }
220
+ )
221
+ },
222
+ {
223
+ label: "Cash",
224
+ active: true,
225
+ content: <ButtonTest></ButtonTest>
226
+ }
227
+ ]
228
+ };
229
+
230
+ const HORIZONTAL = "horizontal";
231
+
232
+ export const tabs = () => (
233
+ <Tabs tabsConfig={tabsConfig} tabsDisplayMode={HORIZONTAL} />
234
+ );
235
+
236
+ const story = page({
237
+ title: "Components|Molecules/Tabs",
238
+ Component: Tabs
239
+ });
240
+
241
+ export default story;
@@ -0,0 +1,9 @@
1
+ const activeTabBackground = "#FFFFFF";
2
+ const activeTabAccent = "#15749D";
3
+ const activeTabHover = "#B8D5E1";
4
+
5
+ export const fallbackValues = {
6
+ activeTabBackground,
7
+ activeTabAccent,
8
+ activeTabHover
9
+ };
@@ -0,0 +1,3 @@
1
+ import Tabs from "./Tabs";
2
+
3
+ export default Tabs;