@apple-pie/slice-native 0.1.4 → 0.1.6
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 +196 -6
- package/dist/cjs/components.js +15 -0
- package/dist/cjs/hooks.js +7 -0
- package/dist/cjs/index.js +18 -812
- package/dist/cjs/providers.js +9 -0
- package/dist/cjs/src/components/SliceButton/SliceButton.js +119 -0
- package/dist/cjs/src/components/SliceIcon/SliceIcon.js +20 -0
- package/dist/cjs/src/components/SliceIcon/iconRegistry.js +668 -0
- package/dist/cjs/src/components/SliceIcon/icons.js +144 -0
- package/dist/cjs/src/components/SliceText/SliceText.js +21 -0
- package/dist/cjs/src/components/SliceTextInput/SliceTextInput.js +87 -0
- package/dist/cjs/src/hooks/useCreateThemedStyles/useCreateThemedStyles.js +13 -0
- package/dist/cjs/src/providers/SliceThemeProvider.js +37 -0
- package/dist/cjs/src/theme/colors/colors.js +253 -0
- package/dist/cjs/src/theme/corners/corners.js +14 -0
- package/dist/cjs/src/theme/elevations/elevations.js +17 -0
- package/dist/cjs/src/theme/motion/motion.js +15 -0
- package/dist/cjs/src/theme/motion.js +47 -0
- package/dist/cjs/src/theme/spacing/spacing.js +14 -0
- package/dist/cjs/src/theme/type/type.js +190 -0
- package/dist/cjs/src/utils/typography/typography.js +17 -0
- package/dist/cjs/theme.js +23 -538
- package/dist/cjs/utils.js +7 -0
- package/dist/esm/components.mjs +5 -0
- package/dist/esm/hooks.mjs +1 -0
- package/dist/esm/index.mjs +8 -813
- package/dist/esm/providers.mjs +1 -0
- package/dist/esm/src/components/SliceButton/SliceButton.mjs +117 -0
- package/dist/esm/src/components/SliceIcon/SliceIcon.mjs +18 -0
- package/dist/esm/src/components/SliceIcon/iconRegistry.mjs +666 -0
- package/dist/esm/src/components/SliceIcon/icons.mjs +142 -0
- package/dist/esm/src/components/SliceText/SliceText.mjs +19 -0
- package/dist/esm/src/components/SliceTextInput/SliceTextInput.mjs +85 -0
- package/dist/esm/src/hooks/useCreateThemedStyles/useCreateThemedStyles.mjs +11 -0
- package/dist/esm/src/providers/SliceThemeProvider.mjs +33 -0
- package/dist/esm/src/theme/colors/colors.mjs +249 -0
- package/dist/esm/src/theme/corners/corners.mjs +12 -0
- package/dist/esm/src/theme/elevations/elevations.mjs +15 -0
- package/dist/esm/src/theme/motion/motion.mjs +13 -0
- package/dist/esm/src/theme/motion.mjs +45 -0
- package/dist/esm/src/theme/spacing/spacing.mjs +12 -0
- package/dist/esm/src/theme/type/type.mjs +184 -0
- package/dist/esm/src/utils/typography/typography.mjs +15 -0
- package/dist/esm/theme.mjs +7 -522
- package/dist/esm/utils.mjs +1 -0
- package/dist/types/native/index.d.ts +8 -4
- package/dist/types/native/src/components/SliceButton/SliceButton.d.ts +5 -0
- package/dist/types/native/src/components/SliceButton/_types.d.ts +47 -0
- package/dist/types/native/src/components/SliceButton/index.d.ts +2 -0
- package/dist/types/native/src/components/SliceIcon/SliceIcon.d.ts +2 -0
- package/dist/types/native/{components/Icon → src/components/SliceIcon}/icons.d.ts +1 -0
- package/dist/types/native/src/components/SliceIcon/index.d.ts +3 -0
- package/dist/types/native/src/components/SliceText/SliceText.d.ts +5 -0
- package/dist/types/native/src/components/SliceText/_types.d.ts +17 -0
- package/dist/types/native/src/components/SliceText/index.d.ts +2 -0
- package/dist/types/native/src/components/SliceTextInput/SliceTextInput.d.ts +2 -0
- package/dist/types/native/src/components/SliceTextInput/_types.d.ts +36 -0
- package/dist/types/native/src/components/SliceTextInput/index.d.ts +2 -0
- package/dist/types/native/src/components/index.d.ts +8 -0
- package/dist/types/native/src/hooks/index.d.ts +1 -0
- package/dist/types/native/src/hooks/useCreateThemedStyles/index.d.ts +1 -0
- package/dist/types/native/src/hooks/useCreateThemedStyles/useCreateThemedStyles.d.ts +7 -0
- package/dist/types/native/src/providers/SliceThemeProvider.d.ts +16 -0
- package/dist/types/native/src/providers/index.d.ts +2 -0
- package/dist/types/native/{theme → src/theme}/index.d.ts +5 -5
- package/dist/types/native/src/utils/index.d.ts +1 -0
- package/dist/types/native/src/utils/typography/index.d.ts +1 -0
- package/dist/types/native/src/utils/typography/typography.d.ts +7 -0
- package/package.json +32 -3
- package/dist/types/native/components/Icon/NativeIcon.d.ts +0 -2
- package/dist/types/native/components/Icon/index.d.ts +0 -3
- /package/dist/types/native/{components/Icon → src/components/SliceIcon}/_types.d.ts +0 -0
- /package/dist/types/native/{components/Icon → src/components/SliceIcon}/iconRegistry.d.ts +0 -0
- /package/dist/types/native/{theme → src/theme}/motion.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SliceThemeProvider, useSliceContext, useSliceTheme } from './src/providers/SliceThemeProvider.mjs';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { StyleSheet, Pressable } from 'react-native';
|
|
4
|
+
import Reanimated from 'react-native-reanimated';
|
|
5
|
+
import { useSliceTheme } from '../../providers/SliceThemeProvider.mjs';
|
|
6
|
+
import { SliceIcon } from '../SliceIcon/SliceIcon.mjs';
|
|
7
|
+
import { StyledText } from '../SliceText/SliceText.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Component logic & render
|
|
11
|
+
*/
|
|
12
|
+
function SliceButton(props) {
|
|
13
|
+
const { colors, name } = useSliceTheme();
|
|
14
|
+
const isLightTheme = name.includes('light');
|
|
15
|
+
const { children, onPress, disabled = false, icon, iconPosition = 'left', iconSize = 24, animatedStyle, variant = 'primary', layout, presence, accessibilityState, ...pressableProps } = props;
|
|
16
|
+
const hasLabel = children !== undefined && children !== null && children !== false && children !== '';
|
|
17
|
+
// adjust padding for the visual discrepancy because of the intrinsic padding of each icon
|
|
18
|
+
const pressableStyle = useMemo(() => {
|
|
19
|
+
if (!hasLabel)
|
|
20
|
+
return StyleSheet.compose(styles.pressable, styles.pressableNoLabel);
|
|
21
|
+
if (icon && iconPosition === 'left')
|
|
22
|
+
return StyleSheet.compose(styles.pressable, styles.pressableIconLeft);
|
|
23
|
+
if (icon && iconPosition === 'right')
|
|
24
|
+
return StyleSheet.compose(styles.pressable, styles.pressableIconRight);
|
|
25
|
+
return styles.pressable;
|
|
26
|
+
}, [icon, iconPosition, hasLabel]);
|
|
27
|
+
// create a round button when the button has no label
|
|
28
|
+
const wrapperStyle = useMemo(() => {
|
|
29
|
+
if (!hasLabel)
|
|
30
|
+
return StyleSheet.compose(styles.wrapper, styles.roundWrapper);
|
|
31
|
+
return styles.wrapper;
|
|
32
|
+
}, [hasLabel]);
|
|
33
|
+
// memoize the color styles to apply to the button/label based on variant and disabled state
|
|
34
|
+
const colorStyles = useMemo(() => {
|
|
35
|
+
const bgColor = variant === 'primary' ? colors['core-button-primary'] : colors['core-surface-primary'];
|
|
36
|
+
const disabledBGColor = disabled ? colors['core-surface-secondary'] : undefined;
|
|
37
|
+
const color = colors['core-text-primary'];
|
|
38
|
+
const disabledColor = disabled ? colors['core-text-disabled'] : undefined;
|
|
39
|
+
const iconColor = disabled
|
|
40
|
+
? disabledColor
|
|
41
|
+
: isLightTheme
|
|
42
|
+
? colors['core-icon-primary']
|
|
43
|
+
: colors['core-link-primary'];
|
|
44
|
+
return StyleSheet.create({
|
|
45
|
+
backgroundColor: {
|
|
46
|
+
backgroundColor: disabledBGColor ?? bgColor,
|
|
47
|
+
},
|
|
48
|
+
textColor: {
|
|
49
|
+
color: disabledColor ?? color,
|
|
50
|
+
},
|
|
51
|
+
ripple: {
|
|
52
|
+
color: 'rgba(255,255,255,0.5)',
|
|
53
|
+
},
|
|
54
|
+
icon: {
|
|
55
|
+
color: iconColor,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}, [variant, disabled, colors, isLightTheme]);
|
|
59
|
+
// primary buttons are full color and have no border
|
|
60
|
+
const borderStyles = useMemo(() => {
|
|
61
|
+
return StyleSheet.create({
|
|
62
|
+
border: {
|
|
63
|
+
borderWidth: variant === 'primary' ? 0 : 1,
|
|
64
|
+
borderColor: colors['core-outline-secondary'],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}, [variant, colors]);
|
|
68
|
+
// disable touch events when button is disabled
|
|
69
|
+
const pointerEvents = useMemo(() => {
|
|
70
|
+
return StyleSheet.create({
|
|
71
|
+
pointer: {
|
|
72
|
+
pointerEvents: disabled ? 'none' : 'auto',
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}, [disabled]);
|
|
76
|
+
return (jsx(Reanimated.View, { layout: layout, children: jsx(Reanimated.View, { entering: presence?.entering, exiting: presence?.exiting, children: jsx(Reanimated.View, { style: [wrapperStyle, pointerEvents.pointer, colorStyles.backgroundColor, borderStyles.border, animatedStyle], children: jsxs(Pressable, { ...pressableProps, accessibilityRole: pressableProps.accessibilityRole ?? 'button', accessibilityState: { ...accessibilityState, disabled }, disabled: disabled, style: pressableStyle, onPress: disabled ? undefined : onPress, android_ripple: pressableProps.android_ripple ?? colorStyles.ripple, children: [icon && iconPosition === 'left' && (jsx(SliceIcon, { name: icon, size: iconSize, strokeColor: colorStyles.icon.color, pointerEvents: "none", accessible: false })), hasLabel && (jsx(StyledText, { textStyle: 'body-xl-bold', style: colorStyles.textColor, singleLine: true, numberOfLines: 1, ellipsizeMode: 'tail', children: children })), icon && iconPosition === 'right' && (jsx(SliceIcon, { name: icon, size: iconSize, strokeColor: colorStyles.icon.color, pointerEvents: "none", accessible: false }))] }) }) }) }));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Base Styles
|
|
80
|
+
*/
|
|
81
|
+
const styles = StyleSheet.create({
|
|
82
|
+
wrapper: {
|
|
83
|
+
borderRadius: 100,
|
|
84
|
+
overflow: 'hidden',
|
|
85
|
+
justifyContent: 'center',
|
|
86
|
+
alignItems: 'center',
|
|
87
|
+
height: 48,
|
|
88
|
+
width: 'auto',
|
|
89
|
+
},
|
|
90
|
+
roundWrapper: {
|
|
91
|
+
borderRadius: 24,
|
|
92
|
+
width: 48,
|
|
93
|
+
height: 48,
|
|
94
|
+
},
|
|
95
|
+
pressable: {
|
|
96
|
+
flex: 1,
|
|
97
|
+
flexDirection: 'row',
|
|
98
|
+
gap: 6,
|
|
99
|
+
paddingHorizontal: 16,
|
|
100
|
+
justifyContent: 'center',
|
|
101
|
+
alignItems: 'center',
|
|
102
|
+
},
|
|
103
|
+
pressableIconLeft: {
|
|
104
|
+
paddingLeft: 16,
|
|
105
|
+
paddingRight: 22,
|
|
106
|
+
},
|
|
107
|
+
pressableIconRight: {
|
|
108
|
+
paddingLeft: 22,
|
|
109
|
+
paddingRight: 16,
|
|
110
|
+
},
|
|
111
|
+
pressableNoLabel: {
|
|
112
|
+
paddingLeft: 0,
|
|
113
|
+
paddingRight: 0,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export { SliceButton };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import { useColorScheme } from 'react-native';
|
|
4
|
+
import Svg from 'react-native-svg';
|
|
5
|
+
import { STATIC_ICON_REGISTRY } from './iconRegistry.mjs';
|
|
6
|
+
|
|
7
|
+
const SliceIcon = memo((props) => {
|
|
8
|
+
const dark = useColorScheme() === 'dark';
|
|
9
|
+
const { name = 'home', size = 20, stroke = 1.5, strokeColor = dark ? '#ffffff' : '#000000', fillColor, fill = false, coverUp = dark ? '#000000' : '#ffffff', toggle = false, disabled = false, onPress, onPressIn, onPressOut, onLongPress, accessibilityState, opacity = 1, ...svgProps } = props;
|
|
10
|
+
const variant = STATIC_ICON_REGISTRY.get(name);
|
|
11
|
+
const shape = toggle ? (variant?.lineOn ?? variant?.line) : variant?.line;
|
|
12
|
+
if (!shape)
|
|
13
|
+
return null;
|
|
14
|
+
return (jsx(Svg, { width: size, height: size, viewBox: "0 0 20 20", fill: "none", accessibilityRole: onPress || onLongPress ? 'button' : 'image', accessibilityLabel: `${name} icon`, ...svgProps, disabled: disabled, opacity: disabled ? Number(opacity) * 0.5 : opacity, accessibilityState: { ...accessibilityState, disabled }, onPress: disabled ? undefined : onPress, onPressIn: disabled ? undefined : onPressIn, onPressOut: disabled ? undefined : onPressOut, onLongPress: disabled ? undefined : onLongPress, children: shape({ stroke, strokeColor, fillColor: fill ? (fillColor ?? (dark ? 0.2 : 0.125)) : 0, coverUp }) }));
|
|
15
|
+
});
|
|
16
|
+
SliceIcon.displayName = 'SliceIcon';
|
|
17
|
+
|
|
18
|
+
export { SliceIcon };
|