cpk-ui 0.8.0-beta.6 → 0.8.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 (31) hide show
  1. package/README.md +18 -14
  2. package/components/uis/Button/Button.d.ts.map +1 -1
  3. package/components/uis/Button/Button.js +3 -10
  4. package/components/uis/Calendar/Calendar.d.ts.map +1 -1
  5. package/components/uis/Calendar/Calendar.js +48 -7
  6. package/components/uis/Calendar/CalendarDay.d.ts.map +1 -1
  7. package/components/uis/Calendar/CalendarDay.js +47 -19
  8. package/components/uis/Calendar/types.d.ts +7 -0
  9. package/components/uis/Calendar/types.d.ts.map +1 -1
  10. package/components/uis/DonutChart/DonutChart.d.ts +24 -0
  11. package/components/uis/DonutChart/DonutChart.d.ts.map +1 -0
  12. package/components/uis/DonutChart/DonutChart.js +73 -0
  13. package/components/uis/LineChart/LineChart.d.ts +37 -0
  14. package/components/uis/LineChart/LineChart.d.ts.map +1 -0
  15. package/components/uis/LineChart/LineChart.js +111 -0
  16. package/components/uis/RadioGroup/RadioButton.d.ts +3 -1
  17. package/components/uis/RadioGroup/RadioButton.d.ts.map +1 -1
  18. package/components/uis/RadioGroup/RadioButton.js +7 -29
  19. package/components/uis/SelectionFeedback/SelectionFeedback.d.ts +21 -0
  20. package/components/uis/SelectionFeedback/SelectionFeedback.d.ts.map +1 -0
  21. package/components/uis/SelectionFeedback/SelectionFeedback.js +47 -0
  22. package/components/uis/TimePicker/TimePicker.d.ts +61 -0
  23. package/components/uis/TimePicker/TimePicker.d.ts.map +1 -0
  24. package/components/uis/TimePicker/TimePicker.js +222 -0
  25. package/components/uis/TimePicker/timeFormat.d.ts +41 -0
  26. package/components/uis/TimePicker/timeFormat.d.ts.map +1 -0
  27. package/components/uis/TimePicker/timeFormat.js +176 -0
  28. package/index.d.ts +4 -0
  29. package/index.d.ts.map +1 -1
  30. package/index.js +4 -0
  31. package/package.json +2 -1
@@ -0,0 +1,176 @@
1
+ /** 9:05 and 21:05: a single digit hour and a day period on each side of noon. */
2
+ const MORNING = new Date(2000, 0, 1, 9, 5);
3
+ const EVENING = new Date(2000, 0, 1, 21, 5);
4
+ const FALLBACK_DAY_PERIODS = ['AM', 'PM'];
5
+ const hasIntl = typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function';
6
+ function createFormat(locale, options) {
7
+ if (!hasIntl) {
8
+ return null;
9
+ }
10
+ try {
11
+ return new Intl.DateTimeFormat(locale, options);
12
+ }
13
+ catch {
14
+ try {
15
+ return new Intl.DateTimeFormat(undefined, options);
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ }
22
+ function partsOf(format, date) {
23
+ if (!format || typeof format.formatToParts !== 'function') {
24
+ return null;
25
+ }
26
+ try {
27
+ return format.formatToParts(date);
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ }
33
+ function isSegment(type) {
34
+ return type === 'hour' || type === 'minute' || type === 'dayPeriod';
35
+ }
36
+ function fallbackFormat(hourCycle = 'h23') {
37
+ return Object.freeze({
38
+ hourCycle,
39
+ separator: ':',
40
+ order: hourCycle === 'h12'
41
+ ? ['hour', 'minute', 'dayPeriod']
42
+ : ['hour', 'minute'],
43
+ dayPeriods: FALLBACK_DAY_PERIODS,
44
+ padHour: hourCycle === 'h23',
45
+ });
46
+ }
47
+ function readDayPeriods(locale) {
48
+ const format = createFormat(locale, {
49
+ hour: 'numeric',
50
+ minute: '2-digit',
51
+ hour12: true,
52
+ });
53
+ const morning = partsOf(format, MORNING)?.find((part) => part.type === 'dayPeriod')?.value;
54
+ const evening = partsOf(format, EVENING)?.find((part) => part.type === 'dayPeriod')?.value;
55
+ return morning && evening && morning !== evening
56
+ ? [morning, evening]
57
+ : FALLBACK_DAY_PERIODS;
58
+ }
59
+ const formatCache = new Map();
60
+ function hasClock(parts) {
61
+ return (parts.some((part) => part.type === 'hour') &&
62
+ parts.some((part) => part.type === 'minute'));
63
+ }
64
+ function readFormat(locale, hourCycle, evening, morning) {
65
+ const cycle = hourCycle ??
66
+ (evening.some((part) => part.type === 'dayPeriod') ? 'h12' : 'h23');
67
+ const types = evening.map((part) => part.type).filter(isSegment);
68
+ const order = types.filter((type, index) => types.indexOf(type) === index &&
69
+ (type !== 'dayPeriod' || cycle === 'h12'));
70
+ if (cycle === 'h12' && !order.includes('dayPeriod')) {
71
+ order.push('dayPeriod');
72
+ }
73
+ const hourIndex = evening.findIndex((part) => part.type === 'hour');
74
+ const minuteIndex = evening.findIndex((part) => part.type === 'minute');
75
+ const separator = minuteIndex > hourIndex
76
+ ? evening
77
+ .slice(hourIndex + 1, minuteIndex)
78
+ .map((part) => part.value)
79
+ .join('')
80
+ .trim()
81
+ : '';
82
+ return Object.freeze({
83
+ hourCycle: cycle,
84
+ separator: separator || ':',
85
+ order,
86
+ dayPeriods: cycle === 'h12' ? readDayPeriods(locale) : FALLBACK_DAY_PERIODS,
87
+ padHour: (morning.find((part) => part.type === 'hour')?.value.length ?? 1) > 1,
88
+ });
89
+ }
90
+ /**
91
+ * Hour cycle, separator, segment order and day period words for `locale`.
92
+ * An explicit `hourCycle` overrides the locale's preference but keeps its words.
93
+ */
94
+ export function resolveTimeFormat(locale, hourCycle) {
95
+ const cacheKey = `${locale}|${hourCycle ?? ''}`;
96
+ const cached = formatCache.get(cacheKey);
97
+ if (cached) {
98
+ return cached;
99
+ }
100
+ const cycle12 = hourCycle === undefined ? {} : { hour12: hourCycle === 'h12' };
101
+ // The short time style is how the locale writes a time (`09:05` in German);
102
+ // `hour: 'numeric'` drops that padding, so it is only the fallback shape.
103
+ const candidates = [
104
+ { timeStyle: 'short', ...cycle12 },
105
+ { hour: 'numeric', minute: '2-digit', ...cycle12 },
106
+ ];
107
+ let resolved = fallbackFormat(hourCycle);
108
+ for (const options of candidates) {
109
+ const format = createFormat(locale, options);
110
+ const evening = partsOf(format, EVENING);
111
+ const morning = partsOf(format, MORNING);
112
+ if (evening && morning && hasClock(evening) && hasClock(morning)) {
113
+ resolved = readFormat(locale, hourCycle, evening, morning);
114
+ break;
115
+ }
116
+ }
117
+ formatCache.set(cacheKey, resolved);
118
+ return resolved;
119
+ }
120
+ /** The hour as a h12 or h23 field shows it. */
121
+ export function displayHour(hours, hourCycle) {
122
+ if (hourCycle === 'h23') {
123
+ return hours;
124
+ }
125
+ return hours % 12 === 0 ? 12 : hours % 12;
126
+ }
127
+ /** A typed hour back to 0–23. */
128
+ export function toHours24(hour, hourCycle, isAfternoon) {
129
+ if (hourCycle === 'h23') {
130
+ return hour;
131
+ }
132
+ return (hour % 12) + (isAfternoon ? 12 : 0);
133
+ }
134
+ export function padTwo(value) {
135
+ return value < 10 ? `0${value}` : String(value);
136
+ }
137
+ const FULL_WIDTH_ZERO = 0xff10;
138
+ /** Full-width digits come from CJK input methods; they type the same numbers. */
139
+ function asciiDigits(text) {
140
+ let digits = '';
141
+ for (const char of text) {
142
+ const code = char.charCodeAt(0);
143
+ if (char >= '0' && char <= '9') {
144
+ digits += char;
145
+ }
146
+ else if (code >= FULL_WIDTH_ZERO && code <= FULL_WIDTH_ZERO + 9) {
147
+ digits += String(code - FULL_WIDTH_ZERO);
148
+ }
149
+ }
150
+ return digits;
151
+ }
152
+ /**
153
+ * Reads one keystroke's worth of field text. Returns `null` when the text can
154
+ * never become a valid value (`25` hours, `60` minutes), so the field keeps
155
+ * its previous draft.
156
+ */
157
+ export function readTimeField(text, field, hourCycle) {
158
+ const digits = asciiDigits(text).slice(0, 2);
159
+ if (digits === '') {
160
+ return { draft: '', value: null, complete: false };
161
+ }
162
+ const value = Number(digits);
163
+ const min = field === 'hour' && hourCycle === 'h12' ? 1 : 0;
164
+ const max = field === 'minute' ? 59 : hourCycle === 'h12' ? 12 : 23;
165
+ if (digits.length === 1) {
166
+ return {
167
+ draft: digits,
168
+ value: value >= min ? value : null,
169
+ complete: value * 10 > max,
170
+ };
171
+ }
172
+ if (value < min || value > max) {
173
+ return null;
174
+ }
175
+ return { draft: digits, value, complete: true };
176
+ }
package/index.d.ts CHANGED
@@ -8,12 +8,14 @@ export * from './components/uis/Calendar/Calendar';
8
8
  export * from './components/uis/Card/Card';
9
9
  export * from './components/uis/Checkbox/Checkbox';
10
10
  export * from './components/uis/CustomPressable/CustomPressable';
11
+ export * from './components/uis/DonutChart/DonutChart';
11
12
  export * from './components/uis/EditText/EditText';
12
13
  export * from './components/uis/Fab/Fab';
13
14
  export * from './components/uis/Hr/Hr';
14
15
  export * from './components/uis/Icon/Icon';
15
16
  export * from './components/uis/IconButton/IconButton';
16
17
  export * from './components/uis/LoadingIndicator/LoadingIndicator';
18
+ export * from './components/uis/LineChart/LineChart';
17
19
  export * from './components/uis/PageIndicator/PageIndicator';
18
20
  export * from './components/uis/PinchZoom/PinchZoom';
19
21
  export * from './components/uis/ParallaxHeader/ParallaxHeader';
@@ -21,8 +23,10 @@ export * from './components/uis/Rating/Rating';
21
23
  export * from './components/uis/ReorderableList/ReorderableList';
22
24
  export * from './components/uis/RadioGroup/RadioGroup';
23
25
  export * from './components/uis/SegmentedControl/SegmentedControl';
26
+ export * from './components/uis/SelectionFeedback/SelectionFeedback';
24
27
  export * from './components/uis/StatusbarBrightness/StatusBarBrightness';
25
28
  export * from './components/uis/SwitchToggle/SwitchToggle';
29
+ export * from './components/uis/TimePicker/TimePicker';
26
30
  export * from './components/uis/Typography/Typography';
27
31
  export * from './hooks';
28
32
  export * from './utils';
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,cAAc,6CAA6C,CAAC;AAC5D,cAAc,uCAAuC,CAAC;AAGtD,cAAc,iDAAiD,CAAC;AAGhE,cAAc,aAAa,CAAC;AAG5B,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,kDAAkD,CAAC;AACjE,cAAc,oCAAoC,CA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,sDAAsD,CAAC;AACrE,cAAc,0DAA0D,CAAC;AACzE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AAGvD,cAAc,SAAS,CAAC;AAGxB,cAAc,SAAS,CAAC;AAGxB,cAAc,SAAS,CAAC"}
package/index.js CHANGED
@@ -12,12 +12,14 @@ export * from './components/uis/Calendar/Calendar';
12
12
  export * from './components/uis/Card/Card';
13
13
  export * from './components/uis/Checkbox/Checkbox';
14
14
  export * from './components/uis/CustomPressable/CustomPressable';
15
+ export * from './components/uis/DonutChart/DonutChart';
15
16
  export * from './components/uis/EditText/EditText';
16
17
  export * from './components/uis/Fab/Fab';
17
18
  export * from './components/uis/Hr/Hr';
18
19
  export * from './components/uis/Icon/Icon';
19
20
  export * from './components/uis/IconButton/IconButton';
20
21
  export * from './components/uis/LoadingIndicator/LoadingIndicator';
22
+ export * from './components/uis/LineChart/LineChart';
21
23
  export * from './components/uis/PageIndicator/PageIndicator';
22
24
  export * from './components/uis/PinchZoom/PinchZoom';
23
25
  export * from './components/uis/ParallaxHeader/ParallaxHeader';
@@ -25,8 +27,10 @@ export * from './components/uis/Rating/Rating';
25
27
  export * from './components/uis/ReorderableList/ReorderableList';
26
28
  export * from './components/uis/RadioGroup/RadioGroup';
27
29
  export * from './components/uis/SegmentedControl/SegmentedControl';
30
+ export * from './components/uis/SelectionFeedback/SelectionFeedback';
28
31
  export * from './components/uis/StatusbarBrightness/StatusBarBrightness';
29
32
  export * from './components/uis/SwitchToggle/SwitchToggle';
33
+ export * from './components/uis/TimePicker/TimePicker';
30
34
  export * from './components/uis/Typography/Typography';
31
35
  // Hooks
32
36
  export * from './hooks';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cpk-ui",
3
- "version": "0.8.0-beta.6",
3
+ "version": "0.8.0",
4
4
  "main": "index",
5
5
  "react-native": "index",
6
6
  "module": "index",
@@ -40,6 +40,7 @@
40
40
  "react-native": ">=0.76",
41
41
  "react-native-gesture-handler": ">=2.28.0",
42
42
  "react-native-reanimated": "^4.1.1",
43
+ "react-native-svg": ">=15",
43
44
  "react-native-worklets": ">=0.5.1 <1",
44
45
  "@expo/vector-icons": "*",
45
46
  "expo-haptics": "*"