@soul-refiner/design-system 0.1.18 → 0.1.20

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 (33) hide show
  1. package/package.json +1 -1
  2. package/src/common/date.ts +30 -0
  3. package/src/common/index.ts +7 -0
  4. package/src/common/styles.ts +2 -2
  5. package/src/components/actions/rate/rate.tsx +1 -1
  6. package/src/components/atoms/box/box.tsx +1 -0
  7. package/src/components/atoms/typography/heading.tsx +1 -1
  8. package/src/components/atoms/typography/paragraph.tsx +0 -1
  9. package/src/components/card/action/action.tsx +106 -0
  10. package/src/components/card/action/index.ts +2 -0
  11. package/src/components/card/audio/audio.tsx +175 -0
  12. package/src/components/card/audio/index.ts +2 -0
  13. package/src/components/card/card.tsx +49 -0
  14. package/src/components/card/feature/feature.tsx +248 -0
  15. package/src/components/card/feature/index.ts +2 -0
  16. package/src/components/card/index.ts +2 -0
  17. package/src/components/card/person/index.ts +2 -0
  18. package/src/components/card/person/person.tsx +96 -0
  19. package/src/components/card/price/index.ts +2 -0
  20. package/src/components/card/price/price.tsx +110 -0
  21. package/src/components/card/regular/index.ts +2 -0
  22. package/src/components/card/regular/regular.tsx +52 -0
  23. package/src/components/card/video/index.ts +2 -0
  24. package/src/components/card/video/video.tsx +167 -0
  25. package/src/components/card/written/index.ts +2 -0
  26. package/src/components/card/written/written.tsx +176 -0
  27. package/src/components/iconography/avatar/avatar.tsx +4 -1
  28. package/src/components/index.ts +1 -0
  29. package/src/components/input/date/date.tsx +694 -0
  30. package/src/components/input/date/index.ts +2 -0
  31. package/src/components/input/index.ts +2 -0
  32. package/src/utils/date.ts +118 -0
  33. package/src/utils/index.ts +13 -0
@@ -0,0 +1,118 @@
1
+ import { THIS_MONTH, THIS_YEAR, CALENDAR_WEEKS } from 'common';
2
+
3
+ export const zeroPad = (value: number, length: number) => {
4
+ return `${value}`.padStart(length, '0');
5
+ };
6
+
7
+ export const getMonthDays = (
8
+ month: number = THIS_MONTH,
9
+ year: number = THIS_YEAR
10
+ ) => {
11
+ const MONTHS_WITH_30 = [4, 6, 9, 11];
12
+ const leapYear = year % 4 === 0;
13
+ return month === 2
14
+ ? leapYear
15
+ ? 29
16
+ : 28
17
+ : MONTHS_WITH_30.includes(month)
18
+ ? 30
19
+ : 31;
20
+ };
21
+
22
+ export const getMonthFirstDay = (month = THIS_MONTH, year = THIS_YEAR) => {
23
+ return +new Date(`${year}-${zeroPad(month, 2)}-01`).getDay() + 1;
24
+ };
25
+
26
+ export const isDate = (date: Date) => {
27
+ const isDate = Object.prototype.toString.call(date) === '[object Date]';
28
+ const isValidDate = date && !Number.isNaN(date.valueOf());
29
+
30
+ return isDate && isValidDate;
31
+ };
32
+
33
+ export const isSameMonth = (date: Date, basedate = new Date()) => {
34
+ if (!(isDate(date) && isDate(basedate))) return false;
35
+ const basedateMonth = +basedate.getMonth() + 1;
36
+ const basedateYear = basedate.getFullYear();
37
+ const dateMonth = +date.getMonth() + 1;
38
+ const dateYear = date.getFullYear();
39
+ return +basedateMonth === +dateMonth && +basedateYear === +dateYear;
40
+ };
41
+
42
+ export const isSameDay = (date: Date, basedate = new Date()) => {
43
+ if (!(isDate(date) && isDate(basedate))) return false;
44
+ const basedateDate = basedate.getDate();
45
+ const basedateMonth = +basedate.getMonth() + 1;
46
+ const basedateYear = basedate.getFullYear();
47
+ const dateDate = date.getDate();
48
+ const dateMonth = +date.getMonth() + 1;
49
+ const dateYear = date.getFullYear();
50
+ return (
51
+ +basedateDate === +dateDate &&
52
+ +basedateMonth === +dateMonth &&
53
+ +basedateYear === +dateYear
54
+ );
55
+ };
56
+
57
+ export const getDateISO = (date = new Date()) => {
58
+ if (!isDate(date)) return null;
59
+ return [
60
+ date.getFullYear(),
61
+ zeroPad(+date.getMonth() + 1, 2),
62
+ zeroPad(+date.getDate(), 2),
63
+ ].join('-');
64
+ };
65
+
66
+ export const getPreviousMonth = (month: number, year: number) => {
67
+ const prevMonth = month > 1 ? month - 1 : 12;
68
+ const prevMonthYear = month > 1 ? year : year - 1;
69
+ return { month: prevMonth, year: prevMonthYear };
70
+ };
71
+
72
+ export const getNextMonth = (month: number, year: number) => {
73
+ const nextMonth = month < 12 ? month + 1 : 1;
74
+ const nextMonthYear = month < 12 ? year : year + 1;
75
+ return { month: nextMonth, year: nextMonthYear };
76
+ };
77
+
78
+ export const buildCalendar = (month = THIS_MONTH, year = THIS_YEAR) => {
79
+ const monthDays = getMonthDays(month, year);
80
+ const monthFirstDay = getMonthFirstDay(month, year);
81
+ const daysFromPrevMonth = monthFirstDay - 1;
82
+ const daysFromNextMonth =
83
+ CALENDAR_WEEKS * 7 - (daysFromPrevMonth + monthDays);
84
+ const { month: prevMonth, year: prevMonthYear } = getPreviousMonth(
85
+ month,
86
+ year
87
+ );
88
+ const { month: nextMonth, year: nextMonthYear } = getNextMonth(month, year);
89
+ const prevMonthDays = getMonthDays(prevMonth, prevMonthYear);
90
+ const prevMonthDates = [...new Array(daysFromPrevMonth)].map((n, index) => {
91
+ const day = index + 1 + (prevMonthDays - daysFromPrevMonth);
92
+ return [prevMonthYear, zeroPad(prevMonth, 2), zeroPad(day, 2)];
93
+ });
94
+ const thisMonthDates = [...new Array(monthDays)].map((n, index) => {
95
+ const day = index + 1;
96
+ return [year, zeroPad(month, 2), zeroPad(day, 2)];
97
+ });
98
+ const nextMonthDates = [...new Array(daysFromNextMonth)].map((n, index) => {
99
+ const day = index + 1;
100
+ return [nextMonthYear, zeroPad(nextMonth, 2), zeroPad(day, 2)];
101
+ });
102
+ return calendarIntoWeeks([
103
+ ...prevMonthDates,
104
+ ...thisMonthDates,
105
+ ...nextMonthDates,
106
+ ]);
107
+ };
108
+
109
+ export const calendarIntoWeeks = (
110
+ calendar: (string | number)[][]
111
+ ): (string | number)[][][] => {
112
+ const res = [];
113
+ while (calendar.length > 0) {
114
+ const chunk = calendar.splice(0, 7);
115
+ res.push(chunk);
116
+ }
117
+ return res;
118
+ };
@@ -0,0 +1,13 @@
1
+ export {
2
+ buildCalendar,
3
+ calendarIntoWeeks,
4
+ getDateISO,
5
+ getMonthDays,
6
+ getMonthFirstDay,
7
+ getNextMonth,
8
+ getPreviousMonth,
9
+ isDate,
10
+ isSameDay,
11
+ isSameMonth,
12
+ zeroPad,
13
+ } from './date';