cpk-ui 0.8.0 → 0.9.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.
- package/README.md +3 -3
- package/components/modals/Snackbar/Snackbar.d.ts.map +1 -1
- package/components/modals/Snackbar/Snackbar.js +37 -14
- package/components/uis/Button/Button.d.ts +3 -1
- package/components/uis/Button/Button.d.ts.map +1 -1
- package/components/uis/Button/Button.js +14 -4
- package/components/uis/Calendar/intl.d.ts.map +1 -1
- package/components/uis/Calendar/intl.js +12 -1
- package/components/uis/EditText/EditText.d.ts +14 -2
- package/components/uis/EditText/EditText.d.ts.map +1 -1
- package/components/uis/EditText/EditText.js +33 -3
- package/components/uis/LineChart/LineChart.d.ts.map +1 -1
- package/components/uis/LineChart/LineChart.js +16 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ maintained by Cross Platform Korea and uses
|
|
|
10
10
|
[kstyled](https://crossplatformkorea.github.io/kstyled) for typed,
|
|
11
11
|
compile-time-aware styling.
|
|
12
12
|
|
|
13
|
-
`cpk-ui@0.
|
|
13
|
+
`cpk-ui@0.9.0` pairs with `kstyled@0.4.1`. Keep the runtime and Babel plugin on
|
|
14
14
|
the same kstyled version.
|
|
15
15
|
|
|
16
16
|
## Install
|
|
@@ -18,7 +18,7 @@ the same kstyled version.
|
|
|
18
18
|
### Expo
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npx expo install cpk-ui@0.
|
|
21
|
+
npx expo install cpk-ui@0.9.0 kstyled@0.4.1 @expo/vector-icons \
|
|
22
22
|
react-native-gesture-handler react-native-svg expo-screen-orientation \
|
|
23
23
|
react-native-reanimated react-native-worklets @shopify/flash-list \
|
|
24
24
|
@expo/match-media expo-haptics
|
|
@@ -31,7 +31,7 @@ Install Expo modules first, then add the same runtime dependencies:
|
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
33
|
npx install-expo-modules@latest
|
|
34
|
-
bun add cpk-ui@0.
|
|
34
|
+
bun add cpk-ui@0.9.0 kstyled@0.4.1 @expo/vector-icons \
|
|
35
35
|
react-native-gesture-handler react-native-svg expo-screen-orientation \
|
|
36
36
|
react-native-reanimated react-native-worklets @shopify/flash-list \
|
|
37
37
|
@expo/match-media expo-haptics
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snackbar.d.ts","sourceRoot":"","sources":["../../../../src/components/modals/Snackbar/Snackbar.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Snackbar.d.ts","sourceRoot":"","sources":["../../../../src/components/modals/Snackbar/Snackbar.tsx"],"names":[],"mappings":"AAAA,OAAO,KASN,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAC,MAAM,cAAc,CAAC;AAMlE,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,EAAS,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAKhE,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AA6CrE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,eAAe,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;IAC/B,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9C,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;;AA2OF,wBAAgF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, { forwardRef, useImperativeHandle, useState, useCallback, useMemo, } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState, useCallback, useMemo, } from 'react';
|
|
3
|
+
import { Animated, Platform, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { useReducedMotion } from 'react-native-reanimated';
|
|
4
5
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
5
6
|
import { styled, css } from 'kstyled';
|
|
6
7
|
import { SnackbarTimer } from './const';
|
|
@@ -20,6 +21,7 @@ const Container = styled(View) `
|
|
|
20
21
|
flex-direction: row;
|
|
21
22
|
justify-content: center;
|
|
22
23
|
`;
|
|
24
|
+
const SNACKBAR_FADE_MS = 200;
|
|
23
25
|
const SnackbarContainer = styled(SafeAreaView) `
|
|
24
26
|
background-color: ${({ theme, $color }) => theme.button[$color].bg};
|
|
25
27
|
border-radius: 8px;
|
|
@@ -49,7 +51,27 @@ function clearTimer() {
|
|
|
49
51
|
function Snackbar({ style }, ref) {
|
|
50
52
|
const [options, setOptions] = useState(null);
|
|
51
53
|
const [visible, setVisible] = useState(false);
|
|
54
|
+
// Stays true through the fade-out so the overlay unmounts only once it is transparent.
|
|
55
|
+
const [rendered, setRendered] = useState(false);
|
|
56
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
57
|
+
const reducedMotion = useReducedMotion();
|
|
52
58
|
const { theme } = useTheme();
|
|
59
|
+
if (visible && !rendered)
|
|
60
|
+
setRendered(true);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!rendered)
|
|
63
|
+
return;
|
|
64
|
+
const animation = Animated.timing(opacity, {
|
|
65
|
+
toValue: visible ? 1 : 0,
|
|
66
|
+
duration: reducedMotion ? 0 : SNACKBAR_FADE_MS,
|
|
67
|
+
useNativeDriver: Platform.OS !== 'web',
|
|
68
|
+
});
|
|
69
|
+
animation.start(({ finished }) => {
|
|
70
|
+
if (finished && !visible)
|
|
71
|
+
setRendered(false);
|
|
72
|
+
});
|
|
73
|
+
return () => animation.stop();
|
|
74
|
+
}, [opacity, reducedMotion, rendered, visible]);
|
|
53
75
|
// Memoize the close handler
|
|
54
76
|
const handleClose = useCallback(() => {
|
|
55
77
|
setVisible(false);
|
|
@@ -124,15 +146,9 @@ function Snackbar({ style }, ref) {
|
|
|
124
146
|
]), [theme.button, color, styles?.actionText]);
|
|
125
147
|
// Memoize action button handler
|
|
126
148
|
const handleActionPress = useCallback(() => setVisible(false), []);
|
|
127
|
-
//
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
flex: 1;
|
|
131
|
-
align-self: stretch;
|
|
132
|
-
`,
|
|
133
|
-
style,
|
|
134
|
-
], [style]);
|
|
135
|
-
const SnackbarContent = useMemo(() => (_jsx(Container, { children: _jsxs(SnackbarContainer, { "$color": color, "$size": size, accessibilityLabel: text, accessibilityLiveRegion: "polite", accessibilityRole: "alert", style: containerStyles, testID: "snackbar-container", children: [_jsx(SnackbarText, { "$color": color, "$size": size, style: textStyles, children: text }), _jsx(ActionContainer, { style: styles?.actionContainer, children: actionText ? (_jsx(Button, { accessibilityLabel: actionText, onPress: handleActionPress, styles: {
|
|
149
|
+
// Only the snackbar surface takes touches; the screen behind stays interactive.
|
|
150
|
+
const overlayStyles = useMemo(() => [layout.overlay, { opacity }, style], [opacity, style]);
|
|
151
|
+
const SnackbarContent = useMemo(() => (_jsx(Container, { style: layout.passThrough, testID: "snackbar-row", children: _jsxs(SnackbarContainer, { "$color": color, "$size": size, accessibilityLabel: text, accessibilityLiveRegion: "polite", accessibilityRole: "alert", style: containerStyles, testID: "snackbar-container", children: [_jsx(SnackbarText, { "$color": color, "$size": size, style: textStyles, children: text }), _jsx(ActionContainer, { style: styles?.actionContainer, children: actionText ? (_jsx(Button, { accessibilityLabel: actionText, onPress: handleActionPress, styles: {
|
|
136
152
|
text: actionTextStyles,
|
|
137
153
|
}, text: actionText, type: "text" })) : (_jsx(Button, { accessibilityLabel: "Dismiss notification", onPress: handleActionPress, text: _jsx(Icon, { color: theme.button[color].text, name: "X", size: sizeConfig.iconSize }), type: "text" })) })] }) })), [
|
|
138
154
|
color,
|
|
@@ -147,9 +163,16 @@ function Snackbar({ style }, ref) {
|
|
|
147
163
|
sizeConfig.iconSize,
|
|
148
164
|
theme.button,
|
|
149
165
|
]);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
_jsx(View, { children: _jsx(Modal, { animationType: "fade", style: modalStyles, transparent: true, visible: visible, children: SnackbarContent }) }));
|
|
166
|
+
// Not a Modal: a native modal window captures every touch on iOS and Android, blocking the screen behind.
|
|
167
|
+
return rendered ? (_jsx(Animated.View, { style: overlayStyles, testID: "snackbar-overlay", children: SnackbarContent })) : null;
|
|
153
168
|
}
|
|
169
|
+
const layout = StyleSheet.create({
|
|
170
|
+
overlay: {
|
|
171
|
+
...StyleSheet.absoluteFillObject,
|
|
172
|
+
pointerEvents: 'box-none',
|
|
173
|
+
zIndex: 1000,
|
|
174
|
+
},
|
|
175
|
+
passThrough: { pointerEvents: 'box-none' },
|
|
176
|
+
});
|
|
154
177
|
// Export memoized component for better performance
|
|
155
178
|
export default React.memo(forwardRef(Snackbar));
|
|
@@ -14,6 +14,8 @@ export type Props = {
|
|
|
14
14
|
loadingColor?: string;
|
|
15
15
|
loadingElement?: ReactElement;
|
|
16
16
|
text?: string | ReactElement;
|
|
17
|
+
/** Maximum lines for a string label. Defaults to 1; `0` lets a long label wrap without a limit. */
|
|
18
|
+
numberOfLines?: number;
|
|
17
19
|
borderRadius?: number;
|
|
18
20
|
startElement?: ReactElement;
|
|
19
21
|
endElement?: ReactElement;
|
|
@@ -35,7 +37,7 @@ type Styles = {
|
|
|
35
37
|
disabledText?: StyleProp<TextStyle>;
|
|
36
38
|
hovered?: StyleProp<ViewStyle>;
|
|
37
39
|
};
|
|
38
|
-
export declare function Button({ testID, type, color, size, disabled, loading, loadingElement, text, startElement, endElement, style, styles, onPress, activeOpacity, touchableHighlightProps, borderRadius, loadingColor, hitSlop, hapticFeedback, accessibilityLabel, }: Props): ReactElement;
|
|
40
|
+
export declare function Button({ testID, type, color, size, disabled, loading, loadingElement, text, numberOfLines, startElement, endElement, style, styles, onPress, activeOpacity, touchableHighlightProps, borderRadius, loadingColor, hitSlop, hapticFeedback, accessibilityLabel, }: Props): ReactElement;
|
|
39
41
|
declare const _default: typeof Button;
|
|
40
42
|
export default _default;
|
|
41
43
|
//# sourceMappingURL=Button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/Button/Button.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAuB,KAAK,YAAY,EAAC,MAAM,OAAO,CAAC;AACrE,OAAO,KAAK,EACV,MAAM,EAEN,SAAS,EACT,SAAS,EACT,uBAAuB,EACvB,SAAS,EACV,MAAM,cAAc,CAAC;AAUtB,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAGxC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AACvD,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,WAAW,GACX,SAAS,GACT,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEnE,MAAM,MAAM,KAAK,GAAG;IAClB,MAAM,CA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YAAY,CAyOtB;wBAGoC,OAAO,MAAM;AAAlD,wBAAmD"}
|
|
@@ -16,7 +16,7 @@ const ButtonContainer = styled.View `
|
|
|
16
16
|
justify-content: center;
|
|
17
17
|
`;
|
|
18
18
|
// Memoize style calculation function
|
|
19
|
-
const calculateStyles = ({ theme, type, color, size, loading, disabled, borderRadius, hovered, styles, }) => {
|
|
19
|
+
const calculateStyles = ({ theme, type, color, size, loading, disabled, borderRadius, hovered, wraps, styles, }) => {
|
|
20
20
|
const isDisabled = disabled || loading;
|
|
21
21
|
const padding = type === 'text'
|
|
22
22
|
? '8px 16px'
|
|
@@ -67,6 +67,7 @@ const calculateStyles = ({ theme, type, color, size, loading, disabled, borderRa
|
|
|
67
67
|
opacity: ${loading ? '0' : '1'};
|
|
68
68
|
gap: 8px;
|
|
69
69
|
`,
|
|
70
|
+
wraps && wrapStyles.content,
|
|
70
71
|
styles?.content,
|
|
71
72
|
],
|
|
72
73
|
loading: [
|
|
@@ -80,6 +81,7 @@ const calculateStyles = ({ theme, type, color, size, loading, disabled, borderRa
|
|
|
80
81
|
css `
|
|
81
82
|
color: ${textColor};
|
|
82
83
|
`,
|
|
84
|
+
wraps && wrapStyles.text,
|
|
83
85
|
styles?.text,
|
|
84
86
|
],
|
|
85
87
|
hovered: hovered
|
|
@@ -110,6 +112,11 @@ const calculateStyles = ({ theme, type, color, size, loading, disabled, borderRa
|
|
|
110
112
|
: undefined,
|
|
111
113
|
};
|
|
112
114
|
};
|
|
115
|
+
// A wrapping label must shrink inside the button row instead of overflowing it.
|
|
116
|
+
const wrapStyles = StyleSheet.create({
|
|
117
|
+
content: { flexShrink: 1 },
|
|
118
|
+
text: { flexShrink: 1, textAlign: 'center' },
|
|
119
|
+
});
|
|
113
120
|
// Memoize button state hook
|
|
114
121
|
const useButtonState = ({ disabled, onPress, loading, }) => {
|
|
115
122
|
return useMemo(() => ({
|
|
@@ -117,7 +124,7 @@ const useButtonState = ({ disabled, onPress, loading, }) => {
|
|
|
117
124
|
isLoading: loading,
|
|
118
125
|
}), [disabled, onPress, loading]);
|
|
119
126
|
};
|
|
120
|
-
export function Button({ testID, type = 'solid', color = 'primary', size = 'medium', disabled, loading = false, loadingElement, text, startElement, endElement, style, styles, onPress, activeOpacity = 0.8, touchableHighlightProps, borderRadius = 4, loadingColor, hitSlop = { top: 8, bottom: 8, left: 8, right: 8 }, hapticFeedback, accessibilityLabel, }) {
|
|
127
|
+
export function Button({ testID, type = 'solid', color = 'primary', size = 'medium', disabled, loading = false, loadingElement, text, numberOfLines = 1, startElement, endElement, style, styles, onPress, activeOpacity = 0.8, touchableHighlightProps, borderRadius = 4, loadingColor, hitSlop = { top: 8, bottom: 8, left: 8, right: 8 }, hapticFeedback, accessibilityLabel, }) {
|
|
121
128
|
const { hovered, hoverProps } = useHoverState();
|
|
122
129
|
const { theme } = useTheme();
|
|
123
130
|
const { innerDisabled } = useButtonState({ disabled, onPress, loading });
|
|
@@ -131,8 +138,10 @@ export function Button({ testID, type = 'solid', color = 'primary', size = 'medi
|
|
|
131
138
|
disabled: innerDisabled,
|
|
132
139
|
borderRadius,
|
|
133
140
|
hovered,
|
|
141
|
+
wraps: numberOfLines !== 1,
|
|
134
142
|
styles,
|
|
135
143
|
}), [
|
|
144
|
+
numberOfLines,
|
|
136
145
|
theme,
|
|
137
146
|
type,
|
|
138
147
|
color,
|
|
@@ -157,8 +166,8 @@ export function Button({ testID, type = 'solid', color = 'primary', size = 'medi
|
|
|
157
166
|
backgroundColor: viewStyle?.backgroundColor,
|
|
158
167
|
color: textStyle?.color,
|
|
159
168
|
}), !text || typeof text === 'string' ? (
|
|
160
|
-
//
|
|
161
|
-
_jsx(Typography.Body2, { numberOfLines:
|
|
169
|
+
// One line by default keeps command labels stable during Android intrinsic remeasurement.
|
|
170
|
+
_jsx(Typography.Body2, { numberOfLines: numberOfLines, style: compositeStyles.text, children: text })) : (text), cloneElemWithDefaultColors({
|
|
162
171
|
element: endElement,
|
|
163
172
|
backgroundColor: viewStyle?.backgroundColor,
|
|
164
173
|
color: textStyle?.color,
|
|
@@ -166,6 +175,7 @@ export function Button({ testID, type = 'solid', color = 'primary', size = 'medi
|
|
|
166
175
|
startElement,
|
|
167
176
|
endElement,
|
|
168
177
|
text,
|
|
178
|
+
numberOfLines,
|
|
169
179
|
compositeStyles.text,
|
|
170
180
|
viewStyle?.backgroundColor,
|
|
171
181
|
textStyle?.color,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/Calendar/intl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,KAAK,KAAK,GACN,YAAY,GACZ,eAAe,GACf,WAAW,GACX,SAAS,GACT,UAAU,CAAC;AAef,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,GACX,IAAI,CAAC,cAAc,GAAG,IAAI,CA2B5B;AAED,oEAAoE;AACpE,wBAAgB,aAAa,IAAI,MAAM,CAUtC;
|
|
1
|
+
{"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/Calendar/intl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,SAAS,CAAC;AAEhD;;;;GAIG;AACH,KAAK,KAAK,GACN,YAAY,GACZ,eAAe,GACf,WAAW,GACX,SAAS,GACT,UAAU,CAAC;AAef,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,GACX,IAAI,CAAC,cAAc,GAAG,IAAI,CA2B5B;AAED,oEAAoE;AACpE,wBAAgB,aAAa,IAAI,MAAM,CAUtC;AA6GD,eAAO,MAAM,kBAAkB,EAAE,kBAM/B,CAAC;AAKH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,kBAAkB,GAAG,MAAM,CActE"}
|
|
@@ -109,9 +109,20 @@ const weekdayLabel = (date, locale) => {
|
|
|
109
109
|
const format = getFormat(locale, 'weekdayNarrow');
|
|
110
110
|
return format ? format.format(date) : FALLBACK_WEEKDAY_NARROW[date.getDay()];
|
|
111
111
|
};
|
|
112
|
+
// Only the number: CJK locales append a day suffix (`2일`, `2日`) that
|
|
113
|
+
// truncates two-digit days in a cell. Native digits (ar-EG) are kept.
|
|
112
114
|
const dayNumber = (date, locale) => {
|
|
113
115
|
const format = getFormat(locale, 'dayNumber');
|
|
114
|
-
|
|
116
|
+
if (!format || typeof format.formatToParts !== 'function') {
|
|
117
|
+
return String(date.getDate());
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const day = format.formatToParts(date).find((part) => part.type === 'day');
|
|
121
|
+
return day ? day.value : String(date.getDate());
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return String(date.getDate());
|
|
125
|
+
}
|
|
115
126
|
};
|
|
116
127
|
const dayAccessibilityLabel = (date, locale) => {
|
|
117
128
|
const format = getFormat(locale, 'dayFull');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MutableRefObject, RefObject } from 'react';
|
|
2
2
|
import React, { type ReactElement } from 'react';
|
|
3
|
-
import type { StyleProp, TextInputProps, TextStyle, ViewStyle } from 'react-native';
|
|
4
|
-
import { TextInput } from 'react-native';
|
|
3
|
+
import type { ColorValue, StyleProp, TextInputProps, TextStyle, ViewStyle } from 'react-native';
|
|
4
|
+
import { Platform, TextInput } from 'react-native';
|
|
5
5
|
export type EditTextStyles = {
|
|
6
6
|
container?: StyleProp<ViewStyle>;
|
|
7
7
|
labelContainer?: StyleProp<ViewStyle>;
|
|
@@ -28,6 +28,18 @@ export declare function editTextInputMetrics(sizeConfig: {
|
|
|
28
28
|
paddingTop: number;
|
|
29
29
|
paddingBottom: number;
|
|
30
30
|
};
|
|
31
|
+
export type EditTextSelectionColors = Pick<TextInputProps, 'selectionColor' | 'cursorColor' | 'selectionHandleColor'>;
|
|
32
|
+
/**
|
|
33
|
+
* Caret, handles and selection highlight for an EditText.
|
|
34
|
+
* iOS draws all three from `selectionColor` (its tint), so it gets the opaque caret colour and derives a
|
|
35
|
+
* translucent highlight itself. Android draws the highlight from `selectionColor` and the caret and handles
|
|
36
|
+
* from `cursorColor` / `selectionHandleColor`, so the highlight stays translucent there.
|
|
37
|
+
*/
|
|
38
|
+
export declare function editTextSelectionColors({ os, caretColor, highlightColor, }: {
|
|
39
|
+
os: typeof Platform.OS;
|
|
40
|
+
caretColor: ColorValue;
|
|
41
|
+
highlightColor: ColorValue;
|
|
42
|
+
}): EditTextSelectionColors;
|
|
31
43
|
export type EditTextProps = {
|
|
32
44
|
testID?: TextInputProps['testID'];
|
|
33
45
|
inputRef?: MutableRefObject<TextInput | undefined> | RefObject<TextInput>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditText.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/EditText/EditText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAa,SAAS,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,EAOZ,KAAK,YAAY,EAClB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"EditText.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/EditText/EditText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAa,SAAS,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,EAOZ,KAAK,YAAY,EAClB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,cAAc,EACd,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,QAAQ,EAER,SAAS,EAGV,MAAM,cAAc,CAAC;AAUtB,MAAM,MAA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, { forwardRef, isValidElement, useCallback, useMemo, useRef, useState, } from 'react';
|
|
3
|
-
import { Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
|
|
3
|
+
import { Platform, Text, TextInput, TouchableWithoutFeedback, View, } from 'react-native';
|
|
4
4
|
import { css } from 'kstyled';
|
|
5
5
|
import { Icon } from '../Icon/Icon';
|
|
6
6
|
import { cloneElemWithDefaultColors } from '../../../utils/guards';
|
|
@@ -17,6 +17,22 @@ export function editTextInputMetrics(sizeConfig) {
|
|
|
17
17
|
paddingBottom: Math.round(sizeConfig.padding * 1.2),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Caret, handles and selection highlight for an EditText.
|
|
22
|
+
* iOS draws all three from `selectionColor` (its tint), so it gets the opaque caret colour and derives a
|
|
23
|
+
* translucent highlight itself. Android draws the highlight from `selectionColor` and the caret and handles
|
|
24
|
+
* from `cursorColor` / `selectionHandleColor`, so the highlight stays translucent there.
|
|
25
|
+
*/
|
|
26
|
+
export function editTextSelectionColors({ os, caretColor, highlightColor, }) {
|
|
27
|
+
if (os === 'android') {
|
|
28
|
+
return {
|
|
29
|
+
selectionColor: highlightColor,
|
|
30
|
+
cursorColor: caretColor,
|
|
31
|
+
selectionHandleColor: caretColor,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return { selectionColor: caretColor };
|
|
35
|
+
}
|
|
20
36
|
export const EditText = forwardRef(({ testID, textInputProps, style, styles, size = 'medium', label, error, startElement, endElement, multiline = false, value = '', placeholder, placeholderColor, onChange, onChangeText, onFocus, onBlur, onSubmitEditing, numberOfLines, maxLength, hideCounter = false, autoComplete, autoCapitalize = 'none', secureTextEntry = false, editable = true, direction = 'column', decoration = 'underline', colors = {}, required = false, accessibilityLabel, }, ref) => {
|
|
21
37
|
EditText.displayName = 'EditText';
|
|
22
38
|
const { theme } = useTheme();
|
|
@@ -199,6 +215,20 @@ export const EditText = forwardRef(({ testID, textInputProps, style, styles, siz
|
|
|
199
215
|
styles?.container,
|
|
200
216
|
]);
|
|
201
217
|
const inputMetrics = useMemo(() => editTextInputMetrics(sizeConfig), [sizeConfig]);
|
|
218
|
+
const callerSelectionColor = textInputProps?.selectionColor;
|
|
219
|
+
// A caller's `selectionColor` keeps React Native's own caret/handle fallback to it.
|
|
220
|
+
const selectionColors = useMemo(() => callerSelectionColor === undefined
|
|
221
|
+
? editTextSelectionColors({
|
|
222
|
+
os: Platform.OS,
|
|
223
|
+
caretColor: colors.focused || theme.text.basic,
|
|
224
|
+
highlightColor: theme.role.underlay,
|
|
225
|
+
})
|
|
226
|
+
: undefined, [
|
|
227
|
+
callerSelectionColor,
|
|
228
|
+
colors.focused,
|
|
229
|
+
theme.text.basic,
|
|
230
|
+
theme.role.underlay,
|
|
231
|
+
]);
|
|
202
232
|
// Memoize render input function
|
|
203
233
|
const renderInput = useCallback(() => {
|
|
204
234
|
return (_jsx(View, { style: [
|
|
@@ -236,7 +266,7 @@ export const EditText = forwardRef(({ testID, textInputProps, style, styles, siz
|
|
|
236
266
|
}, onChange: onChange, onChangeText: onChangeText, onFocus: (e) => {
|
|
237
267
|
setFocused(true);
|
|
238
268
|
onFocus?.(e);
|
|
239
|
-
}, onSubmitEditing: onSubmitEditing, placeholder: placeholder, placeholderTextColor: placeholderColor || theme.text.placeholder, ref: inputRef, secureTextEntry: secureTextEntry,
|
|
269
|
+
}, onSubmitEditing: onSubmitEditing, placeholder: placeholder, placeholderTextColor: placeholderColor || theme.text.placeholder, ref: inputRef, secureTextEntry: secureTextEntry, ...selectionColors, style: [
|
|
240
270
|
{
|
|
241
271
|
color: defaultColor,
|
|
242
272
|
flex: 1,
|
|
@@ -289,13 +319,13 @@ export const EditText = forwardRef(({ testID, textInputProps, style, styles, siz
|
|
|
289
319
|
placeholder,
|
|
290
320
|
placeholderColor,
|
|
291
321
|
secureTextEntry,
|
|
322
|
+
selectionColors,
|
|
292
323
|
sizeConfig,
|
|
293
324
|
startElement,
|
|
294
325
|
styles?.input,
|
|
295
326
|
styles?.inputContainer,
|
|
296
327
|
testID,
|
|
297
328
|
textInputProps,
|
|
298
|
-
theme.role.underlay,
|
|
299
329
|
theme.text.placeholder,
|
|
300
330
|
value,
|
|
301
331
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../../../src/components/uis/LineChart/LineChart.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAoB,KAAK,YAAY,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAYtB,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,SAAS,cAAc,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1D,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CA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AAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1D,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA8CF,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,WAAoB,EACpB,OAAO,EACP,OAAmB,EACnB,QAAe,EACf,UAAsB,EACtB,kBAAkB,EAClB,KAAK,EACL,MAAM,EACN,MAAqB,GACtB,EAAE,cAAc,GAAG,YAAY,CAsM/B"}
|
|
@@ -12,6 +12,13 @@ const BOTTOM_INSET = 30;
|
|
|
12
12
|
function safeNumber(value) {
|
|
13
13
|
return Number.isFinite(value) ? value : 0;
|
|
14
14
|
}
|
|
15
|
+
const FULL_WIDTH = /[\u1100-\u11ff\u2e80-\ua4cf\uac00-\ud7af\uf900-\ufaff\uff00-\uffef]/;
|
|
16
|
+
function estimateTextWidth(text) {
|
|
17
|
+
let width = 0;
|
|
18
|
+
for (const glyph of text)
|
|
19
|
+
width += FULL_WIDTH.test(glyph) ? 11 : 7;
|
|
20
|
+
return width;
|
|
21
|
+
}
|
|
15
22
|
// Each target reaches halfway to its neighbours, so a tap selects the
|
|
16
23
|
// nearest point rather than an equal-width column.
|
|
17
24
|
function targetSlot(points, index, width) {
|
|
@@ -67,6 +74,14 @@ export function LineChart({ data, selectedKey, onSelect, formatValue = String, p
|
|
|
67
74
|
}));
|
|
68
75
|
}, [data, frame.height, frame.width]);
|
|
69
76
|
const selectedPoint = points.find((point) => point.key === selectedKey);
|
|
77
|
+
const tooltipText = selectedPoint ? formatValue(selectedPoint.value) : '';
|
|
78
|
+
// SVG text cannot be measured before paint. At 11pt semibold a Latin glyph
|
|
79
|
+
// or digit needs about 7pt and a full-width CJK glyph about 11pt; the
|
|
80
|
+
// tooltip never grows past the frame.
|
|
81
|
+
const tooltipWidth = Math.min(Math.max(88, estimateTextWidth(tooltipText) + 24), Math.max(88, frame.width - 8));
|
|
82
|
+
const tooltipX = selectedPoint
|
|
83
|
+
? Math.max(4, Math.min(selectedPoint.x - tooltipWidth / 2, frame.width - tooltipWidth - 4))
|
|
84
|
+
: 0;
|
|
70
85
|
// Points are interactive only with `onSelect`; a read-only chart is one
|
|
71
86
|
// image, and interactive point buttons must not nest inside an image.
|
|
72
87
|
const interactive = onSelect !== undefined;
|
|
@@ -95,7 +110,7 @@ export function LineChart({ data, selectedKey, onSelect, formatValue = String, p
|
|
|
95
110
|
: null, points.length > 1 ? (_jsx(Path, { d: makePath(points), fill: "none", stroke: colors.line, strokeLinejoin: "round", strokeWidth: 2.5 })) : null, points.map((point) => {
|
|
96
111
|
const selected = point.key === selectedKey;
|
|
97
112
|
return (_jsxs(G, { children: [_jsx(Circle, { cx: point.x, cy: point.y, fill: selected ? colors.selectedPoint : colors.point, r: selected ? 5 : 3.5, stroke: colors.line, strokeWidth: 2 }), _jsx(SvgText, { fill: colors.label, fontSize: 10, textAnchor: "middle", x: point.x, y: frame.height - 8, children: point.label })] }, point.key));
|
|
98
|
-
}), selectedPoint ? (_jsxs(G, { children: [_jsx(Rect, { fill: colors.tooltipBackground, height: 26, rx: 6, width:
|
|
113
|
+
}), selectedPoint ? (_jsxs(G, { children: [_jsx(Rect, { fill: colors.tooltipBackground, height: 26, rx: 6, testID: `${testID}-tooltip`, width: tooltipWidth, x: tooltipX, y: Math.max(2, selectedPoint.y - 36) }), _jsx(SvgText, { fill: colors.tooltipText, fontSize: 11, fontWeight: "600", textAnchor: "middle", x: tooltipX + tooltipWidth / 2, y: Math.max(19, selectedPoint.y - 19), children: tooltipText })] })) : null, points.length === 0 ? (_jsx(SvgText, { fill: colors.label, fontSize: 13, textAnchor: "middle", testID: `${testID}-empty`, x: frame.width / 2, y: frame.height / 2, children: emptyLabel })) : null] }) }), (interactive ? points : []).map((point, index) => (_jsx(Pressable, { accessibilityLabel: point.accessibilityLabel ??
|
|
99
114
|
`${point.label}: ${formatValue(point.value)}`, accessibilityRole: "button", accessibilityState: { selected: point.key === selectedKey }, onPress: () => {
|
|
100
115
|
const datum = data[point.index];
|
|
101
116
|
if (datum)
|