@onlynative/components 0.1.0 → 0.1.1-alpha.1

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 (70) hide show
  1. package/dist/appbar/index.js +133 -62
  2. package/dist/button/index.js +125 -33
  3. package/dist/card/index.js +88 -20
  4. package/dist/checkbox/index.js +88 -17
  5. package/dist/chip/index.js +122 -30
  6. package/dist/icon-button/index.js +107 -36
  7. package/dist/index.js +335 -251
  8. package/dist/list/index.js +71 -24
  9. package/dist/radio/index.js +43 -14
  10. package/dist/switch/index.js +90 -19
  11. package/dist/text-field/index.js +82 -26
  12. package/package.json +4 -23
  13. package/src/appbar/AppBar.tsx +0 -302
  14. package/src/appbar/index.ts +0 -2
  15. package/src/appbar/styles.ts +0 -92
  16. package/src/appbar/types.ts +0 -67
  17. package/src/button/Button.tsx +0 -133
  18. package/src/button/index.ts +0 -2
  19. package/src/button/styles.ts +0 -287
  20. package/src/button/types.ts +0 -42
  21. package/src/card/Card.tsx +0 -69
  22. package/src/card/index.ts +0 -2
  23. package/src/card/styles.ts +0 -150
  24. package/src/card/types.ts +0 -27
  25. package/src/checkbox/Checkbox.tsx +0 -113
  26. package/src/checkbox/index.ts +0 -2
  27. package/src/checkbox/styles.ts +0 -155
  28. package/src/checkbox/types.ts +0 -20
  29. package/src/chip/Chip.tsx +0 -188
  30. package/src/chip/index.ts +0 -2
  31. package/src/chip/styles.ts +0 -239
  32. package/src/chip/types.ts +0 -58
  33. package/src/icon-button/IconButton.tsx +0 -362
  34. package/src/icon-button/index.ts +0 -6
  35. package/src/icon-button/styles.ts +0 -259
  36. package/src/icon-button/types.ts +0 -55
  37. package/src/index.ts +0 -54
  38. package/src/keyboard-avoiding-wrapper/KeyboardAvoidingWrapper.tsx +0 -69
  39. package/src/keyboard-avoiding-wrapper/index.ts +0 -2
  40. package/src/keyboard-avoiding-wrapper/styles.ts +0 -10
  41. package/src/keyboard-avoiding-wrapper/types.ts +0 -37
  42. package/src/layout/Box.tsx +0 -99
  43. package/src/layout/Column.tsx +0 -16
  44. package/src/layout/Grid.tsx +0 -49
  45. package/src/layout/Layout.tsx +0 -81
  46. package/src/layout/Row.tsx +0 -22
  47. package/src/layout/index.ts +0 -13
  48. package/src/layout/resolveSpacing.ts +0 -11
  49. package/src/layout/types.ts +0 -82
  50. package/src/list/List.tsx +0 -17
  51. package/src/list/ListDivider.tsx +0 -20
  52. package/src/list/ListItem.tsx +0 -128
  53. package/src/list/index.ts +0 -9
  54. package/src/list/styles.ts +0 -132
  55. package/src/list/types.ts +0 -54
  56. package/src/radio/Radio.tsx +0 -103
  57. package/src/radio/index.ts +0 -2
  58. package/src/radio/styles.ts +0 -139
  59. package/src/radio/types.ts +0 -20
  60. package/src/switch/Switch.tsx +0 -121
  61. package/src/switch/index.ts +0 -2
  62. package/src/switch/styles.ts +0 -172
  63. package/src/switch/types.ts +0 -32
  64. package/src/text-field/TextField.tsx +0 -301
  65. package/src/text-field/index.ts +0 -2
  66. package/src/text-field/styles.ts +0 -239
  67. package/src/text-field/types.ts +0 -49
  68. package/src/typography/Typography.tsx +0 -79
  69. package/src/typography/index.ts +0 -3
  70. package/src/typography/types.ts +0 -17
@@ -1,139 +0,0 @@
1
- import { StyleSheet } from 'react-native'
2
- import type { MaterialTheme } from '@onlynative/core'
3
-
4
- import { alphaColor } from '@onlynative/utils'
5
-
6
- interface RadioColors {
7
- borderColor: string
8
- dotColor: string
9
- hoveredBackgroundColor: string
10
- pressedBackgroundColor: string
11
- disabledBorderColor: string
12
- disabledDotColor: string
13
- }
14
-
15
- function getColors(theme: MaterialTheme, selected: boolean): RadioColors {
16
- const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38)
17
-
18
- if (selected) {
19
- return {
20
- borderColor: theme.colors.primary,
21
- dotColor: theme.colors.primary,
22
- hoveredBackgroundColor: alphaColor(
23
- theme.colors.primary,
24
- theme.stateLayer.hoveredOpacity,
25
- ),
26
- pressedBackgroundColor: alphaColor(
27
- theme.colors.primary,
28
- theme.stateLayer.pressedOpacity,
29
- ),
30
- disabledBorderColor: disabledOnSurface38,
31
- disabledDotColor: disabledOnSurface38,
32
- }
33
- }
34
-
35
- return {
36
- borderColor: theme.colors.onSurfaceVariant,
37
- dotColor: 'transparent',
38
- hoveredBackgroundColor: alphaColor(
39
- theme.colors.onSurface,
40
- theme.stateLayer.hoveredOpacity,
41
- ),
42
- pressedBackgroundColor: alphaColor(
43
- theme.colors.onSurface,
44
- theme.stateLayer.pressedOpacity,
45
- ),
46
- disabledBorderColor: disabledOnSurface38,
47
- disabledDotColor: 'transparent',
48
- }
49
- }
50
-
51
- function applyColorOverrides(
52
- theme: MaterialTheme,
53
- colors: RadioColors,
54
- containerColor?: string,
55
- contentColor?: string,
56
- ): RadioColors {
57
- if (!containerColor && !contentColor) return colors
58
-
59
- const result = { ...colors }
60
-
61
- if (containerColor) {
62
- result.borderColor = containerColor
63
- result.dotColor = containerColor
64
- result.hoveredBackgroundColor = alphaColor(
65
- containerColor,
66
- theme.stateLayer.hoveredOpacity,
67
- )
68
- result.pressedBackgroundColor = alphaColor(
69
- containerColor,
70
- theme.stateLayer.pressedOpacity,
71
- )
72
- }
73
-
74
- if (contentColor) {
75
- result.borderColor = contentColor
76
- }
77
-
78
- return result
79
- }
80
-
81
- export function createStyles(
82
- theme: MaterialTheme,
83
- selected: boolean,
84
- containerColor?: string,
85
- contentColor?: string,
86
- ) {
87
- const colors = applyColorOverrides(
88
- theme,
89
- getColors(theme, selected),
90
- containerColor,
91
- contentColor,
92
- )
93
-
94
- const outerSize = 20
95
- const innerSize = 10
96
- const touchTarget = 48
97
-
98
- return StyleSheet.create({
99
- container: {
100
- width: touchTarget,
101
- height: touchTarget,
102
- alignItems: 'center',
103
- justifyContent: 'center',
104
- cursor: 'pointer',
105
- },
106
- hoveredContainer: {
107
- borderRadius: touchTarget / 2,
108
- backgroundColor: colors.hoveredBackgroundColor,
109
- },
110
- pressedContainer: {
111
- borderRadius: touchTarget / 2,
112
- backgroundColor: colors.pressedBackgroundColor,
113
- },
114
- disabledContainer: {
115
- cursor: 'auto',
116
- },
117
- outer: {
118
- width: outerSize,
119
- height: outerSize,
120
- borderRadius: outerSize / 2,
121
- borderWidth: 2,
122
- borderColor: colors.borderColor,
123
- alignItems: 'center' as const,
124
- justifyContent: 'center' as const,
125
- },
126
- disabledOuter: {
127
- borderColor: colors.disabledBorderColor,
128
- },
129
- inner: {
130
- width: innerSize,
131
- height: innerSize,
132
- borderRadius: innerSize / 2,
133
- backgroundColor: colors.dotColor,
134
- },
135
- disabledInner: {
136
- backgroundColor: colors.disabledDotColor,
137
- },
138
- })
139
- }
@@ -1,20 +0,0 @@
1
- import type { PressableProps } from 'react-native'
2
-
3
- export interface RadioProps extends Omit<PressableProps, 'children'> {
4
- /**
5
- * Whether the radio button is selected.
6
- * @default false
7
- */
8
- value?: boolean
9
- /** Callback fired when the radio is pressed. Receives the new value. */
10
- onValueChange?: (value: boolean) => void
11
- /**
12
- * Override the outer ring and inner dot color when selected.
13
- * State-layer colors (hover, press) are derived automatically.
14
- */
15
- containerColor?: string
16
- /**
17
- * Override the outer ring color when unselected.
18
- */
19
- contentColor?: string
20
- }
@@ -1,121 +0,0 @@
1
- import { useMemo } from 'react'
2
- import { Platform, Pressable, StyleSheet, View } from 'react-native'
3
- import type { StyleProp, ViewStyle } from 'react-native'
4
- import { useTheme } from '@onlynative/core'
5
-
6
- import { getMaterialCommunityIcons } from '@onlynative/utils'
7
- import { createStyles } from './styles'
8
- import type { SwitchProps } from './types'
9
-
10
- interface PressableState {
11
- pressed: boolean
12
- hovered?: boolean
13
- }
14
-
15
- function resolveStyle(
16
- trackStyle: StyleProp<ViewStyle>,
17
- hoveredTrackStyle: StyleProp<ViewStyle>,
18
- pressedTrackStyle: StyleProp<ViewStyle>,
19
- disabledTrackStyle: StyleProp<ViewStyle>,
20
- disabled: boolean,
21
- style: SwitchProps['style'],
22
- ): (state: PressableState) => StyleProp<ViewStyle> {
23
- if (typeof style === 'function') {
24
- return (state) => [
25
- trackStyle,
26
- state.hovered && !state.pressed && !disabled
27
- ? hoveredTrackStyle
28
- : undefined,
29
- state.pressed && !disabled ? pressedTrackStyle : undefined,
30
- disabled ? disabledTrackStyle : undefined,
31
- style(state),
32
- ]
33
- }
34
-
35
- return (state) => [
36
- trackStyle,
37
- state.hovered && !state.pressed && !disabled
38
- ? hoveredTrackStyle
39
- : undefined,
40
- state.pressed && !disabled ? pressedTrackStyle : undefined,
41
- disabled ? disabledTrackStyle : undefined,
42
- style,
43
- ]
44
- }
45
-
46
- export function Switch({
47
- style,
48
- value = false,
49
- onValueChange,
50
- selectedIcon = 'check',
51
- unselectedIcon,
52
- containerColor,
53
- contentColor,
54
- disabled = false,
55
- ...props
56
- }: SwitchProps) {
57
- const isDisabled = Boolean(disabled)
58
- const isSelected = Boolean(value)
59
- const hasIcon = isSelected || Boolean(unselectedIcon)
60
-
61
- const theme = useTheme()
62
- const styles = useMemo(
63
- () =>
64
- createStyles(theme, isSelected, hasIcon, containerColor, contentColor),
65
- [theme, isSelected, hasIcon, containerColor, contentColor],
66
- )
67
-
68
- const resolvedIconColor = useMemo(() => {
69
- const base = StyleSheet.flatten([
70
- styles.iconColor,
71
- isDisabled ? styles.disabledIconColor : undefined,
72
- ])
73
- return typeof base?.color === 'string' ? base.color : undefined
74
- }, [styles.iconColor, styles.disabledIconColor, isDisabled])
75
-
76
- const handlePress = () => {
77
- if (!isDisabled) {
78
- onValueChange?.(!isSelected)
79
- }
80
- }
81
-
82
- const iconName = isSelected ? selectedIcon : unselectedIcon
83
- const MaterialCommunityIcons = iconName
84
- ? getMaterialCommunityIcons()
85
- : null
86
- const iconSize = 16
87
-
88
- return (
89
- <Pressable
90
- {...props}
91
- accessibilityRole="switch"
92
- accessibilityState={{
93
- disabled: isDisabled,
94
- checked: isSelected,
95
- }}
96
- hitSlop={Platform.OS === 'web' ? undefined : 4}
97
- disabled={isDisabled}
98
- onPress={handlePress}
99
- style={resolveStyle(
100
- styles.track,
101
- styles.hoveredTrack,
102
- styles.pressedTrack,
103
- styles.disabledTrack,
104
- isDisabled,
105
- style,
106
- )}
107
- >
108
- <View
109
- style={[styles.thumb, isDisabled ? styles.disabledThumb : undefined]}
110
- >
111
- {iconName ? (
112
- <MaterialCommunityIcons
113
- name={iconName}
114
- size={iconSize}
115
- color={resolvedIconColor}
116
- />
117
- ) : null}
118
- </View>
119
- </Pressable>
120
- )
121
- }
@@ -1,2 +0,0 @@
1
- export { Switch } from './Switch'
2
- export type { SwitchProps } from './types'
@@ -1,172 +0,0 @@
1
- import { StyleSheet } from 'react-native'
2
- import type { MaterialTheme } from '@onlynative/core'
3
-
4
- import { alphaColor, blendColor } from '@onlynative/utils'
5
-
6
- interface TrackColors {
7
- trackColor: string
8
- thumbColor: string
9
- iconColor: string
10
- hoveredTrackColor: string
11
- pressedTrackColor: string
12
- borderColor: string
13
- borderWidth: number
14
- disabledTrackColor: string
15
- disabledThumbColor: string
16
- disabledBorderColor: string
17
- disabledBorderWidth: number
18
- }
19
-
20
- function getColors(theme: MaterialTheme, selected: boolean): TrackColors {
21
- const disabledOnSurface12 = alphaColor(theme.colors.onSurface, 0.12)
22
- const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38)
23
-
24
- if (selected) {
25
- return {
26
- trackColor: theme.colors.primary,
27
- thumbColor: theme.colors.onPrimary,
28
- iconColor: theme.colors.onPrimaryContainer,
29
- hoveredTrackColor: blendColor(
30
- theme.colors.primary,
31
- theme.colors.onPrimary,
32
- theme.stateLayer.hoveredOpacity,
33
- ),
34
- pressedTrackColor: blendColor(
35
- theme.colors.primary,
36
- theme.colors.onPrimary,
37
- theme.stateLayer.pressedOpacity,
38
- ),
39
- borderColor: 'transparent',
40
- borderWidth: 0,
41
- disabledTrackColor: disabledOnSurface12,
42
- disabledThumbColor: theme.colors.surface,
43
- disabledBorderColor: 'transparent',
44
- disabledBorderWidth: 0,
45
- }
46
- }
47
-
48
- return {
49
- trackColor: theme.colors.surfaceContainerHighest,
50
- thumbColor: theme.colors.outline,
51
- iconColor: theme.colors.surfaceContainerHighest,
52
- hoveredTrackColor: blendColor(
53
- theme.colors.surfaceContainerHighest,
54
- theme.colors.onSurface,
55
- theme.stateLayer.hoveredOpacity,
56
- ),
57
- pressedTrackColor: blendColor(
58
- theme.colors.surfaceContainerHighest,
59
- theme.colors.onSurface,
60
- theme.stateLayer.pressedOpacity,
61
- ),
62
- borderColor: theme.colors.outline,
63
- borderWidth: 2,
64
- disabledTrackColor: disabledOnSurface12,
65
- disabledThumbColor: disabledOnSurface38,
66
- disabledBorderColor: disabledOnSurface12,
67
- disabledBorderWidth: 2,
68
- }
69
- }
70
-
71
- function applyColorOverrides(
72
- theme: MaterialTheme,
73
- colors: TrackColors,
74
- containerColor?: string,
75
- contentColor?: string,
76
- ): TrackColors {
77
- if (!containerColor && !contentColor) return colors
78
-
79
- const result = { ...colors }
80
-
81
- if (contentColor) {
82
- result.thumbColor = contentColor
83
- result.iconColor = contentColor
84
- }
85
-
86
- if (containerColor) {
87
- const overlay = contentColor ?? colors.thumbColor
88
- result.trackColor = containerColor
89
- result.borderColor = containerColor
90
- result.hoveredTrackColor = blendColor(
91
- containerColor,
92
- overlay,
93
- theme.stateLayer.hoveredOpacity,
94
- )
95
- result.pressedTrackColor = blendColor(
96
- containerColor,
97
- overlay,
98
- theme.stateLayer.pressedOpacity,
99
- )
100
- if (contentColor) {
101
- result.iconColor = containerColor
102
- }
103
- }
104
-
105
- return result
106
- }
107
-
108
- export function createStyles(
109
- theme: MaterialTheme,
110
- selected: boolean,
111
- hasIcon: boolean,
112
- containerColor?: string,
113
- contentColor?: string,
114
- ) {
115
- const colors = applyColorOverrides(
116
- theme,
117
- getColors(theme, selected),
118
- containerColor,
119
- contentColor,
120
- )
121
-
122
- const thumbSize = selected || hasIcon ? 24 : 16
123
- const trackWidth = 52
124
- const trackHeight = 32
125
- const trackPadding = 4
126
- const thumbOffset = selected
127
- ? trackWidth - trackPadding - thumbSize
128
- : trackPadding
129
-
130
- return StyleSheet.create({
131
- track: {
132
- width: trackWidth,
133
- height: trackHeight,
134
- borderRadius: trackHeight / 2,
135
- backgroundColor: colors.trackColor,
136
- borderColor: colors.borderColor,
137
- borderWidth: colors.borderWidth,
138
- justifyContent: 'center',
139
- cursor: 'pointer',
140
- },
141
- hoveredTrack: {
142
- backgroundColor: colors.hoveredTrackColor,
143
- },
144
- pressedTrack: {
145
- backgroundColor: colors.pressedTrackColor,
146
- },
147
- disabledTrack: {
148
- backgroundColor: colors.disabledTrackColor,
149
- borderColor: colors.disabledBorderColor,
150
- borderWidth: colors.disabledBorderWidth,
151
- cursor: 'auto',
152
- },
153
- thumb: {
154
- width: thumbSize,
155
- height: thumbSize,
156
- borderRadius: thumbSize / 2,
157
- backgroundColor: colors.thumbColor,
158
- marginStart: thumbOffset,
159
- alignItems: 'center' as const,
160
- justifyContent: 'center' as const,
161
- },
162
- disabledThumb: {
163
- backgroundColor: colors.disabledThumbColor,
164
- },
165
- iconColor: {
166
- color: colors.iconColor,
167
- },
168
- disabledIconColor: {
169
- color: alphaColor(theme.colors.onSurface, 0.38),
170
- },
171
- })
172
- }
@@ -1,32 +0,0 @@
1
- import type MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
- import type { ComponentProps } from 'react'
3
- import type { PressableProps } from 'react-native'
4
-
5
- export interface SwitchProps extends Omit<PressableProps, 'children'> {
6
- /**
7
- * Whether the switch is toggled on.
8
- * @default false
9
- */
10
- value?: boolean
11
- /** Callback fired when the switch is toggled. Receives the new value. */
12
- onValueChange?: (value: boolean) => void
13
- /**
14
- * Name of a MaterialCommunityIcons icon to show on the thumb when selected.
15
- * @default 'check'
16
- */
17
- selectedIcon?: ComponentProps<typeof MaterialCommunityIcons>['name']
18
- /**
19
- * Name of a MaterialCommunityIcons icon to show on the thumb when unselected.
20
- * When provided, the thumb renders at the larger selected size.
21
- */
22
- unselectedIcon?: ComponentProps<typeof MaterialCommunityIcons>['name']
23
- /**
24
- * Override the track color.
25
- * State-layer colors (hover, press) are derived automatically.
26
- */
27
- containerColor?: string
28
- /**
29
- * Override the thumb and icon color.
30
- */
31
- contentColor?: string
32
- }