@thecb/components 7.7.0-beta.0 → 7.7.0-beta.2

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.
@@ -1,6 +1,7 @@
1
1
  import React, { Fragment } from "react";
2
2
  import numeral from "numeral";
3
- import { CHARADE_GREY } from "../constants/colors";
3
+ import { CHARADE_GREY, ASH_GREY, FIRE_YELLOW } from "../constants/colors";
4
+ import Text from "../components/atoms/text";
4
5
 
5
6
  export const noop = () => {};
6
7
 
@@ -144,3 +145,67 @@ export const throttle = (delay, fn) => {
144
145
  return fn(...args);
145
146
  };
146
147
  };
148
+
149
+ export const titleCaseWord = word => {
150
+ return word.charAt(0).toUpperCase() + word.slice(1);
151
+ };
152
+
153
+ export const titleCaseString = string => {
154
+ return string
155
+ .split(" ")
156
+ .map((word, index, string) =>
157
+ index === 0 || index === string.length - 1 || word.length > 3
158
+ ? titleCaseWord(word.toLowerCase())
159
+ : word
160
+ )
161
+ .join(" ");
162
+ };
163
+
164
+ export const renderCardStatus = (
165
+ expirationStatus,
166
+ expireDate,
167
+ textAlign = "right",
168
+ as = "span"
169
+ ) => {
170
+ const ACTIVE = "ACTIVE";
171
+ const EXPIRING_SOON = "EXPIRING_SOON";
172
+ const EXPIRED = "EXPIRED";
173
+
174
+ switch (expirationStatus) {
175
+ case ACTIVE:
176
+ return (
177
+ <Text
178
+ as={as}
179
+ variant="pXS"
180
+ color={ASH_GREY}
181
+ extraStyles={`text-align: ${textAlign};`}
182
+ >
183
+ Exp Date {expireDate}
184
+ </Text>
185
+ );
186
+ case EXPIRING_SOON:
187
+ return (
188
+ <Text
189
+ as={as}
190
+ variant="pXS"
191
+ color={FIRE_YELLOW}
192
+ extraStyles={`text-align: ${textAlign};`}
193
+ >
194
+ Expiring Soon {expireDate}
195
+ </Text>
196
+ );
197
+ case EXPIRED:
198
+ return (
199
+ <Text
200
+ as={as}
201
+ variant="pXS"
202
+ color={ASH_GREY}
203
+ extraStyles={`text-align: ${textAlign};`}
204
+ >
205
+ Expired
206
+ </Text>
207
+ );
208
+ default:
209
+ null;
210
+ }
211
+ };