@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.
- package/dist/appbar/index.js +133 -62
- package/dist/button/index.js +125 -33
- package/dist/card/index.js +88 -20
- package/dist/checkbox/index.js +88 -17
- package/dist/chip/index.js +122 -30
- package/dist/icon-button/index.js +107 -36
- package/dist/index.js +335 -251
- package/dist/list/index.js +71 -24
- package/dist/radio/index.js +43 -14
- package/dist/switch/index.js +90 -19
- package/dist/text-field/index.js +82 -26
- package/package.json +4 -23
- package/src/appbar/AppBar.tsx +0 -302
- package/src/appbar/index.ts +0 -2
- package/src/appbar/styles.ts +0 -92
- package/src/appbar/types.ts +0 -67
- package/src/button/Button.tsx +0 -133
- package/src/button/index.ts +0 -2
- package/src/button/styles.ts +0 -287
- package/src/button/types.ts +0 -42
- package/src/card/Card.tsx +0 -69
- package/src/card/index.ts +0 -2
- package/src/card/styles.ts +0 -150
- package/src/card/types.ts +0 -27
- package/src/checkbox/Checkbox.tsx +0 -113
- package/src/checkbox/index.ts +0 -2
- package/src/checkbox/styles.ts +0 -155
- package/src/checkbox/types.ts +0 -20
- package/src/chip/Chip.tsx +0 -188
- package/src/chip/index.ts +0 -2
- package/src/chip/styles.ts +0 -239
- package/src/chip/types.ts +0 -58
- package/src/icon-button/IconButton.tsx +0 -362
- package/src/icon-button/index.ts +0 -6
- package/src/icon-button/styles.ts +0 -259
- package/src/icon-button/types.ts +0 -55
- package/src/index.ts +0 -54
- package/src/keyboard-avoiding-wrapper/KeyboardAvoidingWrapper.tsx +0 -69
- package/src/keyboard-avoiding-wrapper/index.ts +0 -2
- package/src/keyboard-avoiding-wrapper/styles.ts +0 -10
- package/src/keyboard-avoiding-wrapper/types.ts +0 -37
- package/src/layout/Box.tsx +0 -99
- package/src/layout/Column.tsx +0 -16
- package/src/layout/Grid.tsx +0 -49
- package/src/layout/Layout.tsx +0 -81
- package/src/layout/Row.tsx +0 -22
- package/src/layout/index.ts +0 -13
- package/src/layout/resolveSpacing.ts +0 -11
- package/src/layout/types.ts +0 -82
- package/src/list/List.tsx +0 -17
- package/src/list/ListDivider.tsx +0 -20
- package/src/list/ListItem.tsx +0 -128
- package/src/list/index.ts +0 -9
- package/src/list/styles.ts +0 -132
- package/src/list/types.ts +0 -54
- package/src/radio/Radio.tsx +0 -103
- package/src/radio/index.ts +0 -2
- package/src/radio/styles.ts +0 -139
- package/src/radio/types.ts +0 -20
- package/src/switch/Switch.tsx +0 -121
- package/src/switch/index.ts +0 -2
- package/src/switch/styles.ts +0 -172
- package/src/switch/types.ts +0 -32
- package/src/text-field/TextField.tsx +0 -301
- package/src/text-field/index.ts +0 -2
- package/src/text-field/styles.ts +0 -239
- package/src/text-field/types.ts +0 -49
- package/src/typography/Typography.tsx +0 -79
- package/src/typography/index.ts +0 -3
- package/src/typography/types.ts +0 -17
package/src/card/styles.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native'
|
|
2
|
-
import type { MaterialTheme } from '@onlynative/core'
|
|
3
|
-
|
|
4
|
-
import type { CardVariant } from './types'
|
|
5
|
-
import { alphaColor, blendColor, elevationStyle } from '@onlynative/utils'
|
|
6
|
-
|
|
7
|
-
interface VariantColors {
|
|
8
|
-
backgroundColor: string
|
|
9
|
-
borderColor: string
|
|
10
|
-
borderWidth: number
|
|
11
|
-
hoveredBackgroundColor: string
|
|
12
|
-
pressedBackgroundColor: string
|
|
13
|
-
disabledBackgroundColor: string
|
|
14
|
-
disabledBorderColor: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getVariantColors(theme: MaterialTheme, variant: CardVariant): VariantColors {
|
|
18
|
-
const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12)
|
|
19
|
-
const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12)
|
|
20
|
-
|
|
21
|
-
if (variant === 'outlined') {
|
|
22
|
-
return {
|
|
23
|
-
backgroundColor: theme.colors.surface,
|
|
24
|
-
borderColor: theme.colors.outline,
|
|
25
|
-
borderWidth: 1,
|
|
26
|
-
hoveredBackgroundColor: alphaColor(
|
|
27
|
-
theme.colors.onSurface,
|
|
28
|
-
theme.stateLayer.hoveredOpacity,
|
|
29
|
-
),
|
|
30
|
-
pressedBackgroundColor: alphaColor(
|
|
31
|
-
theme.colors.onSurface,
|
|
32
|
-
theme.stateLayer.pressedOpacity,
|
|
33
|
-
),
|
|
34
|
-
disabledBackgroundColor: theme.colors.surface,
|
|
35
|
-
disabledBorderColor: disabledOutlineColor,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (variant === 'filled') {
|
|
40
|
-
return {
|
|
41
|
-
backgroundColor: theme.colors.surfaceContainerHighest,
|
|
42
|
-
borderColor: 'transparent',
|
|
43
|
-
borderWidth: 0,
|
|
44
|
-
hoveredBackgroundColor: blendColor(
|
|
45
|
-
theme.colors.surfaceContainerHighest,
|
|
46
|
-
theme.colors.onSurface,
|
|
47
|
-
theme.stateLayer.hoveredOpacity,
|
|
48
|
-
),
|
|
49
|
-
pressedBackgroundColor: blendColor(
|
|
50
|
-
theme.colors.surfaceContainerHighest,
|
|
51
|
-
theme.colors.onSurface,
|
|
52
|
-
theme.stateLayer.pressedOpacity,
|
|
53
|
-
),
|
|
54
|
-
disabledBackgroundColor: disabledContainerColor,
|
|
55
|
-
disabledBorderColor: 'transparent',
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// elevated (default)
|
|
60
|
-
return {
|
|
61
|
-
backgroundColor: theme.colors.surface,
|
|
62
|
-
borderColor: 'transparent',
|
|
63
|
-
borderWidth: 0,
|
|
64
|
-
hoveredBackgroundColor: blendColor(
|
|
65
|
-
theme.colors.surface,
|
|
66
|
-
theme.colors.onSurface,
|
|
67
|
-
theme.stateLayer.hoveredOpacity,
|
|
68
|
-
),
|
|
69
|
-
pressedBackgroundColor: blendColor(
|
|
70
|
-
theme.colors.surface,
|
|
71
|
-
theme.colors.onSurface,
|
|
72
|
-
theme.stateLayer.pressedOpacity,
|
|
73
|
-
),
|
|
74
|
-
disabledBackgroundColor: disabledContainerColor,
|
|
75
|
-
disabledBorderColor: 'transparent',
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function applyColorOverrides(
|
|
80
|
-
theme: MaterialTheme,
|
|
81
|
-
colors: VariantColors,
|
|
82
|
-
containerColor?: string,
|
|
83
|
-
): VariantColors {
|
|
84
|
-
if (!containerColor) return colors
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
...colors,
|
|
88
|
-
backgroundColor: containerColor,
|
|
89
|
-
borderColor: containerColor,
|
|
90
|
-
borderWidth: 0,
|
|
91
|
-
hoveredBackgroundColor: blendColor(
|
|
92
|
-
containerColor,
|
|
93
|
-
theme.colors.onSurface,
|
|
94
|
-
theme.stateLayer.hoveredOpacity,
|
|
95
|
-
),
|
|
96
|
-
pressedBackgroundColor: blendColor(
|
|
97
|
-
containerColor,
|
|
98
|
-
theme.colors.onSurface,
|
|
99
|
-
theme.stateLayer.pressedOpacity,
|
|
100
|
-
),
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function createStyles(
|
|
105
|
-
theme: MaterialTheme,
|
|
106
|
-
variant: CardVariant,
|
|
107
|
-
containerColor?: string,
|
|
108
|
-
) {
|
|
109
|
-
const baseColors = getVariantColors(theme, variant)
|
|
110
|
-
const colors = applyColorOverrides(theme, baseColors, containerColor)
|
|
111
|
-
const elevationLevel0 = elevationStyle(theme.elevation.level0)
|
|
112
|
-
const elevationLevel1 = elevationStyle(theme.elevation.level1)
|
|
113
|
-
const elevationLevel2 = elevationStyle(theme.elevation.level2)
|
|
114
|
-
const baseElevation =
|
|
115
|
-
variant === 'elevated' ? elevationLevel1 : elevationLevel0
|
|
116
|
-
|
|
117
|
-
return StyleSheet.create({
|
|
118
|
-
container: {
|
|
119
|
-
borderRadius: theme.shape.cornerMedium,
|
|
120
|
-
backgroundColor: colors.backgroundColor,
|
|
121
|
-
borderColor: colors.borderColor,
|
|
122
|
-
borderWidth: colors.borderWidth,
|
|
123
|
-
overflow: 'hidden',
|
|
124
|
-
...baseElevation,
|
|
125
|
-
},
|
|
126
|
-
interactiveContainer: {
|
|
127
|
-
cursor: 'pointer',
|
|
128
|
-
},
|
|
129
|
-
hoveredContainer: {
|
|
130
|
-
backgroundColor: colors.hoveredBackgroundColor,
|
|
131
|
-
...(variant === 'elevated'
|
|
132
|
-
? elevationLevel2
|
|
133
|
-
: variant === 'filled'
|
|
134
|
-
? elevationLevel1
|
|
135
|
-
: undefined),
|
|
136
|
-
},
|
|
137
|
-
pressedContainer: {
|
|
138
|
-
backgroundColor: colors.pressedBackgroundColor,
|
|
139
|
-
},
|
|
140
|
-
disabledContainer: {
|
|
141
|
-
backgroundColor: colors.disabledBackgroundColor,
|
|
142
|
-
borderColor: colors.disabledBorderColor,
|
|
143
|
-
cursor: 'auto',
|
|
144
|
-
...elevationLevel0,
|
|
145
|
-
},
|
|
146
|
-
disabledContent: {
|
|
147
|
-
opacity: theme.stateLayer.disabledOpacity,
|
|
148
|
-
},
|
|
149
|
-
})
|
|
150
|
-
}
|
package/src/card/types.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react'
|
|
2
|
-
import type { ViewProps } from 'react-native'
|
|
3
|
-
|
|
4
|
-
/** Surface style variant of the card following Material Design 3 roles. */
|
|
5
|
-
export type CardVariant = 'elevated' | 'filled' | 'outlined'
|
|
6
|
-
|
|
7
|
-
export interface CardProps extends ViewProps {
|
|
8
|
-
/** Content rendered inside the card surface. */
|
|
9
|
-
children: ReactNode
|
|
10
|
-
/**
|
|
11
|
-
* Surface style variant.
|
|
12
|
-
* @default 'elevated'
|
|
13
|
-
*/
|
|
14
|
-
variant?: CardVariant
|
|
15
|
-
/** When provided, the card becomes interactive (Pressable). Omit to render as a plain View. */
|
|
16
|
-
onPress?: () => void
|
|
17
|
-
/**
|
|
18
|
-
* Disables the press interaction and reduces opacity. Only effective when `onPress` is provided.
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
disabled?: boolean
|
|
22
|
-
/**
|
|
23
|
-
* Override the container (background) color.
|
|
24
|
-
* State-layer colors (hover, press) are derived automatically.
|
|
25
|
-
*/
|
|
26
|
-
containerColor?: string
|
|
27
|
-
}
|
|
@@ -1,113 +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 { CheckboxProps } from './types'
|
|
9
|
-
|
|
10
|
-
interface PressableState {
|
|
11
|
-
pressed: boolean
|
|
12
|
-
hovered?: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function resolveStyle(
|
|
16
|
-
containerStyle: StyleProp<ViewStyle>,
|
|
17
|
-
hoveredContainerStyle: StyleProp<ViewStyle>,
|
|
18
|
-
pressedContainerStyle: StyleProp<ViewStyle>,
|
|
19
|
-
disabledContainerStyle: StyleProp<ViewStyle>,
|
|
20
|
-
disabled: boolean,
|
|
21
|
-
style: CheckboxProps['style'],
|
|
22
|
-
): (state: PressableState) => StyleProp<ViewStyle> {
|
|
23
|
-
if (typeof style === 'function') {
|
|
24
|
-
return (state) => [
|
|
25
|
-
containerStyle,
|
|
26
|
-
state.hovered && !state.pressed && !disabled
|
|
27
|
-
? hoveredContainerStyle
|
|
28
|
-
: undefined,
|
|
29
|
-
state.pressed && !disabled ? pressedContainerStyle : undefined,
|
|
30
|
-
disabled ? disabledContainerStyle : undefined,
|
|
31
|
-
style(state),
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return (state) => [
|
|
36
|
-
containerStyle,
|
|
37
|
-
state.hovered && !state.pressed && !disabled
|
|
38
|
-
? hoveredContainerStyle
|
|
39
|
-
: undefined,
|
|
40
|
-
state.pressed && !disabled ? pressedContainerStyle : undefined,
|
|
41
|
-
disabled ? disabledContainerStyle : undefined,
|
|
42
|
-
style,
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function Checkbox({
|
|
47
|
-
style,
|
|
48
|
-
value = false,
|
|
49
|
-
onValueChange,
|
|
50
|
-
containerColor,
|
|
51
|
-
contentColor,
|
|
52
|
-
disabled = false,
|
|
53
|
-
...props
|
|
54
|
-
}: CheckboxProps) {
|
|
55
|
-
const isDisabled = Boolean(disabled)
|
|
56
|
-
const isChecked = Boolean(value)
|
|
57
|
-
|
|
58
|
-
const MaterialCommunityIcons = isChecked
|
|
59
|
-
? getMaterialCommunityIcons()
|
|
60
|
-
: null
|
|
61
|
-
|
|
62
|
-
const theme = useTheme()
|
|
63
|
-
const styles = useMemo(
|
|
64
|
-
() => createStyles(theme, isChecked, containerColor, contentColor),
|
|
65
|
-
[theme, isChecked, 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?.(!isChecked)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<Pressable
|
|
84
|
-
{...props}
|
|
85
|
-
accessibilityRole="checkbox"
|
|
86
|
-
accessibilityState={{
|
|
87
|
-
disabled: isDisabled,
|
|
88
|
-
checked: isChecked,
|
|
89
|
-
}}
|
|
90
|
-
hitSlop={Platform.OS === 'web' ? undefined : 4}
|
|
91
|
-
disabled={isDisabled}
|
|
92
|
-
onPress={handlePress}
|
|
93
|
-
style={resolveStyle(
|
|
94
|
-
styles.container,
|
|
95
|
-
styles.hoveredContainer,
|
|
96
|
-
styles.pressedContainer,
|
|
97
|
-
styles.disabledContainer,
|
|
98
|
-
isDisabled,
|
|
99
|
-
style,
|
|
100
|
-
)}
|
|
101
|
-
>
|
|
102
|
-
<View style={[styles.box, isDisabled ? styles.disabledBox : undefined]}>
|
|
103
|
-
{isChecked ? (
|
|
104
|
-
<MaterialCommunityIcons
|
|
105
|
-
name="check"
|
|
106
|
-
size={14}
|
|
107
|
-
color={resolvedIconColor}
|
|
108
|
-
/>
|
|
109
|
-
) : null}
|
|
110
|
-
</View>
|
|
111
|
-
</Pressable>
|
|
112
|
-
)
|
|
113
|
-
}
|
package/src/checkbox/index.ts
DELETED
package/src/checkbox/styles.ts
DELETED
|
@@ -1,155 +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 BoxColors {
|
|
7
|
-
backgroundColor: string
|
|
8
|
-
borderColor: string
|
|
9
|
-
borderWidth: number
|
|
10
|
-
iconColor: string
|
|
11
|
-
hoveredBackgroundColor: string
|
|
12
|
-
pressedBackgroundColor: string
|
|
13
|
-
disabledBackgroundColor: string
|
|
14
|
-
disabledBorderColor: string
|
|
15
|
-
disabledBorderWidth: number
|
|
16
|
-
disabledIconColor: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getColors(theme: MaterialTheme, checked: boolean): BoxColors {
|
|
20
|
-
const disabledOnSurface38 = alphaColor(theme.colors.onSurface, 0.38)
|
|
21
|
-
|
|
22
|
-
if (checked) {
|
|
23
|
-
return {
|
|
24
|
-
backgroundColor: theme.colors.primary,
|
|
25
|
-
borderColor: 'transparent',
|
|
26
|
-
borderWidth: 0,
|
|
27
|
-
iconColor: theme.colors.onPrimary,
|
|
28
|
-
hoveredBackgroundColor: blendColor(
|
|
29
|
-
theme.colors.primary,
|
|
30
|
-
theme.colors.onPrimary,
|
|
31
|
-
theme.stateLayer.hoveredOpacity,
|
|
32
|
-
),
|
|
33
|
-
pressedBackgroundColor: blendColor(
|
|
34
|
-
theme.colors.primary,
|
|
35
|
-
theme.colors.onPrimary,
|
|
36
|
-
theme.stateLayer.pressedOpacity,
|
|
37
|
-
),
|
|
38
|
-
disabledBackgroundColor: disabledOnSurface38,
|
|
39
|
-
disabledBorderColor: 'transparent',
|
|
40
|
-
disabledBorderWidth: 0,
|
|
41
|
-
disabledIconColor: theme.colors.surface,
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
backgroundColor: 'transparent',
|
|
47
|
-
borderColor: theme.colors.onSurfaceVariant,
|
|
48
|
-
borderWidth: 2,
|
|
49
|
-
iconColor: 'transparent',
|
|
50
|
-
hoveredBackgroundColor: alphaColor(
|
|
51
|
-
theme.colors.onSurface,
|
|
52
|
-
theme.stateLayer.hoveredOpacity,
|
|
53
|
-
),
|
|
54
|
-
pressedBackgroundColor: alphaColor(
|
|
55
|
-
theme.colors.onSurface,
|
|
56
|
-
theme.stateLayer.pressedOpacity,
|
|
57
|
-
),
|
|
58
|
-
disabledBackgroundColor: 'transparent',
|
|
59
|
-
disabledBorderColor: disabledOnSurface38,
|
|
60
|
-
disabledBorderWidth: 2,
|
|
61
|
-
disabledIconColor: 'transparent',
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function applyColorOverrides(
|
|
66
|
-
theme: MaterialTheme,
|
|
67
|
-
colors: BoxColors,
|
|
68
|
-
containerColor?: string,
|
|
69
|
-
contentColor?: string,
|
|
70
|
-
): BoxColors {
|
|
71
|
-
if (!containerColor && !contentColor) return colors
|
|
72
|
-
|
|
73
|
-
const result = { ...colors }
|
|
74
|
-
|
|
75
|
-
if (contentColor) {
|
|
76
|
-
result.iconColor = contentColor
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (containerColor) {
|
|
80
|
-
const overlay = contentColor ?? colors.iconColor
|
|
81
|
-
result.backgroundColor = containerColor
|
|
82
|
-
result.borderColor = containerColor
|
|
83
|
-
result.hoveredBackgroundColor = blendColor(
|
|
84
|
-
containerColor,
|
|
85
|
-
overlay,
|
|
86
|
-
theme.stateLayer.hoveredOpacity,
|
|
87
|
-
)
|
|
88
|
-
result.pressedBackgroundColor = blendColor(
|
|
89
|
-
containerColor,
|
|
90
|
-
overlay,
|
|
91
|
-
theme.stateLayer.pressedOpacity,
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return result
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function createStyles(
|
|
99
|
-
theme: MaterialTheme,
|
|
100
|
-
checked: boolean,
|
|
101
|
-
containerColor?: string,
|
|
102
|
-
contentColor?: string,
|
|
103
|
-
) {
|
|
104
|
-
const colors = applyColorOverrides(
|
|
105
|
-
theme,
|
|
106
|
-
getColors(theme, checked),
|
|
107
|
-
containerColor,
|
|
108
|
-
contentColor,
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
const size = 18
|
|
112
|
-
const touchTarget = 48
|
|
113
|
-
|
|
114
|
-
return StyleSheet.create({
|
|
115
|
-
container: {
|
|
116
|
-
width: touchTarget,
|
|
117
|
-
height: touchTarget,
|
|
118
|
-
alignItems: 'center',
|
|
119
|
-
justifyContent: 'center',
|
|
120
|
-
cursor: 'pointer',
|
|
121
|
-
},
|
|
122
|
-
hoveredContainer: {
|
|
123
|
-
borderRadius: touchTarget / 2,
|
|
124
|
-
backgroundColor: colors.hoveredBackgroundColor,
|
|
125
|
-
},
|
|
126
|
-
pressedContainer: {
|
|
127
|
-
borderRadius: touchTarget / 2,
|
|
128
|
-
backgroundColor: colors.pressedBackgroundColor,
|
|
129
|
-
},
|
|
130
|
-
disabledContainer: {
|
|
131
|
-
cursor: 'auto',
|
|
132
|
-
},
|
|
133
|
-
box: {
|
|
134
|
-
width: size,
|
|
135
|
-
height: size,
|
|
136
|
-
borderRadius: theme.shape.cornerExtraSmall,
|
|
137
|
-
backgroundColor: colors.backgroundColor,
|
|
138
|
-
borderColor: colors.borderColor,
|
|
139
|
-
borderWidth: colors.borderWidth,
|
|
140
|
-
alignItems: 'center' as const,
|
|
141
|
-
justifyContent: 'center' as const,
|
|
142
|
-
},
|
|
143
|
-
disabledBox: {
|
|
144
|
-
backgroundColor: colors.disabledBackgroundColor,
|
|
145
|
-
borderColor: colors.disabledBorderColor,
|
|
146
|
-
borderWidth: colors.disabledBorderWidth,
|
|
147
|
-
},
|
|
148
|
-
iconColor: {
|
|
149
|
-
color: colors.iconColor,
|
|
150
|
-
},
|
|
151
|
-
disabledIconColor: {
|
|
152
|
-
color: colors.disabledIconColor,
|
|
153
|
-
},
|
|
154
|
-
})
|
|
155
|
-
}
|
package/src/checkbox/types.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { PressableProps } from 'react-native'
|
|
2
|
-
|
|
3
|
-
export interface CheckboxProps extends Omit<PressableProps, 'children'> {
|
|
4
|
-
/**
|
|
5
|
-
* Whether the checkbox is checked.
|
|
6
|
-
* @default false
|
|
7
|
-
*/
|
|
8
|
-
value?: boolean
|
|
9
|
-
/** Callback fired when the checkbox is toggled. Receives the new value. */
|
|
10
|
-
onValueChange?: (value: boolean) => void
|
|
11
|
-
/**
|
|
12
|
-
* Override the container (box) color when checked.
|
|
13
|
-
* State-layer colors (hover, press) are derived automatically.
|
|
14
|
-
*/
|
|
15
|
-
containerColor?: string
|
|
16
|
-
/**
|
|
17
|
-
* Override the checkmark icon color.
|
|
18
|
-
*/
|
|
19
|
-
contentColor?: string
|
|
20
|
-
}
|
package/src/chip/Chip.tsx
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import { Platform, Pressable, StyleSheet, Text, 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 { ChipProps } from './types'
|
|
9
|
-
|
|
10
|
-
interface PressableState {
|
|
11
|
-
pressed: boolean
|
|
12
|
-
hovered?: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function resolveStyle(
|
|
16
|
-
containerStyle: StyleProp<ViewStyle>,
|
|
17
|
-
hoveredContainerStyle: StyleProp<ViewStyle>,
|
|
18
|
-
pressedContainerStyle: StyleProp<ViewStyle>,
|
|
19
|
-
disabledContainerStyle: StyleProp<ViewStyle>,
|
|
20
|
-
disabled: boolean,
|
|
21
|
-
style: ChipProps['style'],
|
|
22
|
-
): (state: PressableState) => StyleProp<ViewStyle> {
|
|
23
|
-
if (typeof style === 'function') {
|
|
24
|
-
return (state) => [
|
|
25
|
-
containerStyle,
|
|
26
|
-
state.hovered && !state.pressed && !disabled
|
|
27
|
-
? hoveredContainerStyle
|
|
28
|
-
: undefined,
|
|
29
|
-
state.pressed && !disabled ? pressedContainerStyle : undefined,
|
|
30
|
-
disabled ? disabledContainerStyle : undefined,
|
|
31
|
-
style(state),
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return (state) => [
|
|
36
|
-
containerStyle,
|
|
37
|
-
state.hovered && !state.pressed && !disabled
|
|
38
|
-
? hoveredContainerStyle
|
|
39
|
-
: undefined,
|
|
40
|
-
state.pressed && !disabled ? pressedContainerStyle : undefined,
|
|
41
|
-
disabled ? disabledContainerStyle : undefined,
|
|
42
|
-
style,
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function Chip({
|
|
47
|
-
children,
|
|
48
|
-
style,
|
|
49
|
-
variant = 'assist',
|
|
50
|
-
elevated = false,
|
|
51
|
-
selected = false,
|
|
52
|
-
leadingIcon,
|
|
53
|
-
iconSize = 18,
|
|
54
|
-
avatar,
|
|
55
|
-
onClose,
|
|
56
|
-
containerColor,
|
|
57
|
-
contentColor,
|
|
58
|
-
labelStyle: labelStyleOverride,
|
|
59
|
-
disabled = false,
|
|
60
|
-
...props
|
|
61
|
-
}: ChipProps) {
|
|
62
|
-
const isDisabled = Boolean(disabled)
|
|
63
|
-
const isSelected = variant === 'filter' ? Boolean(selected) : false
|
|
64
|
-
|
|
65
|
-
const showCloseIcon =
|
|
66
|
-
onClose !== undefined &&
|
|
67
|
-
(variant === 'input' || (variant === 'filter' && isSelected))
|
|
68
|
-
|
|
69
|
-
const hasLeadingContent = Boolean(
|
|
70
|
-
(variant === 'input' && avatar) ||
|
|
71
|
-
leadingIcon ||
|
|
72
|
-
(variant === 'filter' && isSelected),
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
const needsIcons =
|
|
76
|
-
Boolean(leadingIcon) || (variant === 'filter' && isSelected) || showCloseIcon
|
|
77
|
-
const MaterialCommunityIcons = needsIcons
|
|
78
|
-
? getMaterialCommunityIcons()
|
|
79
|
-
: null
|
|
80
|
-
|
|
81
|
-
const theme = useTheme()
|
|
82
|
-
const styles = useMemo(
|
|
83
|
-
() =>
|
|
84
|
-
createStyles(
|
|
85
|
-
theme,
|
|
86
|
-
variant,
|
|
87
|
-
elevated,
|
|
88
|
-
isSelected,
|
|
89
|
-
hasLeadingContent,
|
|
90
|
-
showCloseIcon,
|
|
91
|
-
containerColor,
|
|
92
|
-
contentColor,
|
|
93
|
-
),
|
|
94
|
-
[
|
|
95
|
-
theme,
|
|
96
|
-
variant,
|
|
97
|
-
elevated,
|
|
98
|
-
isSelected,
|
|
99
|
-
hasLeadingContent,
|
|
100
|
-
showCloseIcon,
|
|
101
|
-
containerColor,
|
|
102
|
-
contentColor,
|
|
103
|
-
],
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
const resolvedIconColor = useMemo(() => {
|
|
107
|
-
const base = StyleSheet.flatten([
|
|
108
|
-
styles.label,
|
|
109
|
-
isDisabled ? styles.disabledLabel : undefined,
|
|
110
|
-
])
|
|
111
|
-
return typeof base?.color === 'string' ? base.color : undefined
|
|
112
|
-
}, [styles.label, styles.disabledLabel, isDisabled])
|
|
113
|
-
|
|
114
|
-
const computedLabelStyle = useMemo(
|
|
115
|
-
() => [
|
|
116
|
-
styles.label,
|
|
117
|
-
isDisabled ? styles.disabledLabel : undefined,
|
|
118
|
-
labelStyleOverride,
|
|
119
|
-
],
|
|
120
|
-
[isDisabled, styles.disabledLabel, styles.label, labelStyleOverride],
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
const renderLeadingContent = () => {
|
|
124
|
-
if (variant === 'input' && avatar) {
|
|
125
|
-
return <View style={styles.avatar}>{avatar}</View>
|
|
126
|
-
}
|
|
127
|
-
if (leadingIcon) {
|
|
128
|
-
return (
|
|
129
|
-
<MaterialCommunityIcons
|
|
130
|
-
name={leadingIcon}
|
|
131
|
-
size={iconSize}
|
|
132
|
-
color={resolvedIconColor}
|
|
133
|
-
style={styles.leadingIcon}
|
|
134
|
-
/>
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
if (variant === 'filter' && isSelected) {
|
|
138
|
-
return (
|
|
139
|
-
<MaterialCommunityIcons
|
|
140
|
-
name="check"
|
|
141
|
-
size={iconSize}
|
|
142
|
-
color={resolvedIconColor}
|
|
143
|
-
style={styles.leadingIcon}
|
|
144
|
-
/>
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
return null
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
<Pressable
|
|
152
|
-
{...props}
|
|
153
|
-
accessibilityRole="button"
|
|
154
|
-
accessibilityState={{
|
|
155
|
-
disabled: isDisabled,
|
|
156
|
-
...(variant === 'filter' ? { selected: isSelected } : undefined),
|
|
157
|
-
}}
|
|
158
|
-
hitSlop={Platform.OS === 'web' ? undefined : 4}
|
|
159
|
-
disabled={isDisabled}
|
|
160
|
-
style={resolveStyle(
|
|
161
|
-
styles.container,
|
|
162
|
-
styles.hoveredContainer,
|
|
163
|
-
styles.pressedContainer,
|
|
164
|
-
styles.disabledContainer,
|
|
165
|
-
isDisabled,
|
|
166
|
-
style,
|
|
167
|
-
)}
|
|
168
|
-
>
|
|
169
|
-
{renderLeadingContent()}
|
|
170
|
-
<Text style={computedLabelStyle}>{children}</Text>
|
|
171
|
-
{showCloseIcon ? (
|
|
172
|
-
<Pressable
|
|
173
|
-
onPress={onClose}
|
|
174
|
-
accessibilityRole="button"
|
|
175
|
-
accessibilityLabel="Remove"
|
|
176
|
-
hitSlop={4}
|
|
177
|
-
style={styles.closeButton}
|
|
178
|
-
>
|
|
179
|
-
<MaterialCommunityIcons
|
|
180
|
-
name="close"
|
|
181
|
-
size={iconSize}
|
|
182
|
-
color={resolvedIconColor}
|
|
183
|
-
/>
|
|
184
|
-
</Pressable>
|
|
185
|
-
) : null}
|
|
186
|
-
</Pressable>
|
|
187
|
-
)
|
|
188
|
-
}
|
package/src/chip/index.ts
DELETED