@hzblj/kara-components 0.16.0 → 0.17.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/CHANGELOG.md +13 -0
- package/lib/module/atoms/picker/picker.ios.js +27 -15
- package/lib/module/atoms/picker/picker.ios.js.map +1 -1
- package/lib/typescript/atoms/picker/picker.ios.d.ts +5 -3
- package/lib/typescript/atoms/picker/picker.types.d.ts +11 -3
- package/package.json +4 -4
- package/src/atoms/picker/picker.ios.tsx +46 -16
- package/src/atoms/picker/picker.types.ts +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @hzblj/kara-components
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#54](https://github.com/hzblj/kara-ui/pull/54) [`76f14b5`](https://github.com/hzblj/kara-ui/commit/76f14b5e71bdbb8fb431502a987e776243015177) Thanks [@hzblj](https://github.com/hzblj)! - `Picker` takes `pickerStyle` on iOS: `wheel`, as before and still the default, or `menu`, a button with the selection, in the accent, that opens the options as a menu. A screen with more than one picker, or a picker in a row, no longer has to give the screen to wheels. Android ignores it: its exposed dropdown is a menu already.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @hzblj/kara-theme@0.17.0
|
|
13
|
+
- @hzblj/kara-sx@0.17.0
|
|
14
|
+
- @hzblj/kara-native@0.17.0
|
|
15
|
+
|
|
3
16
|
## 0.16.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -1,39 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { Picker as NativePicker } from '@expo/ui/community/picker';
|
|
4
|
-
import { Picker as SwiftUIPicker, Text as SwiftUIText } from '@expo/ui/swift-ui';
|
|
5
|
-
import { disabled as disabledModifier, foregroundStyle, pickerStyle, tag } from '@expo/ui/swift-ui/modifiers';
|
|
4
|
+
import { Host, Picker as SwiftUIPicker, Text as SwiftUIText } from '@expo/ui/swift-ui';
|
|
5
|
+
import { disabled as disabledModifier, foregroundStyle, pickerStyle as pickerStyleModifier, tag, tint } from '@expo/ui/swift-ui/modifiers';
|
|
6
6
|
import { useAppTheme } from '@hzblj/kara-theme';
|
|
7
7
|
import { useCallback, useMemo } from 'react';
|
|
8
8
|
import { useInsideHost } from "../../host-context.js";
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
/**
|
|
11
|
-
* A SwiftUI
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* A SwiftUI picker: a wheel, or with `pickerStyle="menu"` a button with the selection that opens the options as a
|
|
12
|
+
* menu, in the accent. On its own the wheel is `@expo/ui`'s community picker, which brings a host of its own, and the
|
|
13
|
+
* menu sits in a host sized to its button on both axes, as the date picker's pill does, so it drops into a row the way
|
|
14
|
+
* a `Text` does. Inside a `Screen` or `Island` either renders into that host instead (see `useInsideHost`): a host
|
|
15
|
+
* nested in the island's stack is given no height there, and the wheel spills over the views around it.
|
|
14
16
|
*/
|
|
15
17
|
export const Picker = ({
|
|
16
18
|
disabled = false,
|
|
17
19
|
onValueChange,
|
|
18
20
|
options,
|
|
21
|
+
pickerStyle = 'wheel',
|
|
19
22
|
testID,
|
|
20
23
|
value
|
|
21
24
|
}) => {
|
|
22
25
|
const theme = useAppTheme();
|
|
23
26
|
const insideHost = useInsideHost();
|
|
24
27
|
const color = theme.colorString('content.primary');
|
|
28
|
+
const menu = pickerStyle === 'menu';
|
|
25
29
|
const onChange = useCallback(next => onValueChange?.(String(next)), [onValueChange]);
|
|
26
|
-
const
|
|
30
|
+
const modifiers = useMemo(() => [pickerStyleModifier(pickerStyle), ...(menu ? [tint(theme.color('fill.accent.primary'))] : []), ...(disabled ? [disabledModifier(true)] : [])], [disabled, menu, pickerStyle, theme]);
|
|
31
|
+
const picker = /*#__PURE__*/_jsx(SwiftUIPicker, {
|
|
32
|
+
modifiers: modifiers,
|
|
33
|
+
onSelectionChange: onChange,
|
|
34
|
+
selection: value,
|
|
35
|
+
testID: testID,
|
|
36
|
+
children: options.map(option => /*#__PURE__*/_jsx(SwiftUIText, {
|
|
37
|
+
modifiers: [tag(option.value), foregroundStyle(color)],
|
|
38
|
+
children: option.label
|
|
39
|
+
}, option.value))
|
|
40
|
+
});
|
|
27
41
|
if (insideHost) {
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
children: option.label
|
|
36
|
-
}, option.value))
|
|
42
|
+
return picker;
|
|
43
|
+
}
|
|
44
|
+
if (menu) {
|
|
45
|
+
return /*#__PURE__*/_jsx(Host, {
|
|
46
|
+
colorScheme: theme.dark ? 'dark' : 'light',
|
|
47
|
+
matchContents: true,
|
|
48
|
+
children: picker
|
|
37
49
|
});
|
|
38
50
|
}
|
|
39
51
|
return /*#__PURE__*/_jsx(NativePicker, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Picker","NativePicker","SwiftUIPicker","Text","SwiftUIText","disabled","disabledModifier","foregroundStyle","pickerStyle","tag","useAppTheme","useCallback","useMemo","useInsideHost","jsx","_jsx","onValueChange","options","testID","value","theme","insideHost","color","colorString","onChange","next","String","
|
|
1
|
+
{"version":3,"names":["Picker","NativePicker","Host","SwiftUIPicker","Text","SwiftUIText","disabled","disabledModifier","foregroundStyle","pickerStyle","pickerStyleModifier","tag","tint","useAppTheme","useCallback","useMemo","useInsideHost","jsx","_jsx","onValueChange","options","testID","value","theme","insideHost","color","colorString","menu","onChange","next","String","modifiers","picker","onSelectionChange","selection","children","map","option","label","colorScheme","dark","matchContents","enabled","selectedValue","Item"],"sourceRoot":"../../../../src","sources":["atoms/picker/picker.ios.tsx"],"mappings":";;AAAA,SAAQA,MAAM,IAAIC,YAAY,QAAO,2BAA2B;AAChE,S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M,gBACVd,IAAA,CAACf,aAAa;IAAC4B,SAAS,EAAEA,SAAU;IAACE,iBAAiB,EAAEL,QAAS;IAACM,SAAS,EAAEZ,KAAM;IAACD,MAAM,EAAEA,MAAO;IAAAc,QAAA,EAChGf,OAAO,CAACgB,GAAG,CAACC,MAAM,iBACjBnB,IAAA,CAACb,WAAW;MAAoB0B,SAAS,EAAE,CAACpB,GAAG,CAAC0B,MAAM,CAACf,KAAK,CAAC,EAAEd,eAAe,CAACiB,KAAK,CAAC,CAAE;MAAAU,QAAA,EACpFE,MAAM,CAACC;IAAK,GADGD,MAAM,CAACf,KAEZ,CACd;EAAC,CACW,CAChB;EAED,IAAIE,UAAU,EAAE;IACd,OAAOQ,MAAM;EACf;EAEA,IAAIL,IAAI,EAAE;IACR,oBACET,IAAA,CAAChB,IAAI;MAACqC,WAAW,EAAEhB,KAAK,CAACiB,IAAI,GAAG,MAAM,GAAG,OAAQ;MAACC,aAAa;MAAAN,QAAA,EAC5DH;IAAM,CACH,CAAC;EAEX;EAEA,oBACEd,IAAA,CAACjB,YAAY;IAACyC,OAAO,EAAE,CAACpC,QAAS;IAACa,aAAa,EAAES,QAAS;IAACe,aAAa,EAAErB,KAAM;IAACD,MAAM,EAAEA,MAAO;IAAAc,QAAA,EAC7Ff,OAAO,CAACgB,GAAG,CAACC,MAAM,iBACjBnB,IAAA,CAACjB,YAAY,CAAC2C,IAAI;MAACnB,KAAK,EAAEA,KAAM;MAAoBa,KAAK,EAAED,MAAM,CAACC,KAAM;MAAChB,KAAK,EAAEe,MAAM,CAACf;IAAM,GAAvDe,MAAM,CAACf,KAAkD,CAChG;EAAC,CACU,CAAC;AAEnB,CAAC","ignoreList":[]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { PickerComponent } from './picker.types';
|
|
2
2
|
/**
|
|
3
|
-
* A SwiftUI
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* A SwiftUI picker: a wheel, or with `pickerStyle="menu"` a button with the selection that opens the options as a
|
|
4
|
+
* menu, in the accent. On its own the wheel is `@expo/ui`'s community picker, which brings a host of its own, and the
|
|
5
|
+
* menu sits in a host sized to its button on both axes, as the date picker's pill does, so it drops into a row the way
|
|
6
|
+
* a `Text` does. Inside a `Screen` or `Island` either renders into that host instead (see `useInsideHost`): a host
|
|
7
|
+
* nested in the island's stack is given no height there, and the wheel spills over the views around it.
|
|
6
8
|
*/
|
|
7
9
|
export declare const Picker: PickerComponent;
|
|
@@ -6,10 +6,12 @@ export type PickerOption = {
|
|
|
6
6
|
/** What `onValueChange` reports. It also keys the option, so it must be unique. */
|
|
7
7
|
value: string;
|
|
8
8
|
};
|
|
9
|
+
/** How SwiftUI shows the picker: a wheel, or a button that opens the options as a menu. */
|
|
10
|
+
export type PickerStyleName = 'menu' | 'wheel';
|
|
9
11
|
/**
|
|
10
|
-
* A single choice from a list: a SwiftUI
|
|
11
|
-
* own host, so it renders outside `Screen` and `Island` as well. Inside one it
|
|
12
|
-
* can share a stack with other native views.
|
|
12
|
+
* A single choice from a list: a SwiftUI picker on iOS (a wheel, or a menu with `pickerStyle`), Material's exposed
|
|
13
|
+
* dropdown on Android. It brings its own host, so it renders outside `Screen` and `Island` as well. Inside one it
|
|
14
|
+
* renders into that host instead, so it can share a stack with other native views.
|
|
13
15
|
*/
|
|
14
16
|
export type PickerProps = {
|
|
15
17
|
/** Stops the user changing the selection, and dims the picker. */
|
|
@@ -18,6 +20,12 @@ export type PickerProps = {
|
|
|
18
20
|
onValueChange?: (value: string) => void;
|
|
19
21
|
/** The choices, in order. */
|
|
20
22
|
options: PickerOption[];
|
|
23
|
+
/**
|
|
24
|
+
* SwiftUI's picker style. `wheel` by default: the options on a wheel, always in view. `menu` is a button with the
|
|
25
|
+
* selection, in the accent, that opens the options as a menu: what a screen with more than one picker, or a picker
|
|
26
|
+
* in a row, wants. iOS only. Android ignores it: its exposed dropdown is a menu already.
|
|
27
|
+
*/
|
|
28
|
+
pickerStyle?: PickerStyleName;
|
|
21
29
|
/**
|
|
22
30
|
* Android: the dropdown field's test tag. iOS: the wheel's, inside a `Screen` or `Island` only; on its own,
|
|
23
31
|
* `@expo/ui`'s wheel picker drops it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzblj/kara-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "The atoms, molecules, organisms and templates of @hzblj/kara-ui — real SwiftUI and Jetpack Compose views through @expo/ui.",
|
|
5
5
|
"author": "Jan Blazej",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@hzblj/expo-native-icons": "^0.1.0",
|
|
63
63
|
"@hzblj/expo-rich-haptics": "^0.1.0",
|
|
64
|
-
"@hzblj/kara-native": "^0.
|
|
65
|
-
"@hzblj/kara-sx": "^0.
|
|
66
|
-
"@hzblj/kara-theme": "^0.
|
|
64
|
+
"@hzblj/kara-native": "^0.17.0",
|
|
65
|
+
"@hzblj/kara-sx": "^0.17.0",
|
|
66
|
+
"@hzblj/kara-theme": "^0.17.0",
|
|
67
67
|
"sf-symbols-typescript": "^2.2.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {Picker as NativePicker} from '@expo/ui/community/picker'
|
|
2
|
-
import {Picker as SwiftUIPicker, Text as SwiftUIText} from '@expo/ui/swift-ui'
|
|
3
|
-
import {
|
|
2
|
+
import {Host, Picker as SwiftUIPicker, Text as SwiftUIText} from '@expo/ui/swift-ui'
|
|
3
|
+
import {
|
|
4
|
+
disabled as disabledModifier,
|
|
5
|
+
foregroundStyle,
|
|
6
|
+
pickerStyle as pickerStyleModifier,
|
|
7
|
+
tag,
|
|
8
|
+
tint,
|
|
9
|
+
} from '@expo/ui/swift-ui/modifiers'
|
|
4
10
|
import {useAppTheme} from '@hzblj/kara-theme'
|
|
5
11
|
import {useCallback, useMemo} from 'react'
|
|
6
12
|
|
|
@@ -8,30 +14,54 @@ import {useInsideHost} from '../../host-context'
|
|
|
8
14
|
import type {PickerComponent, PickerProps} from './picker.types'
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
|
-
* A SwiftUI
|
|
12
|
-
*
|
|
13
|
-
*
|
|
17
|
+
* A SwiftUI picker: a wheel, or with `pickerStyle="menu"` a button with the selection that opens the options as a
|
|
18
|
+
* menu, in the accent. On its own the wheel is `@expo/ui`'s community picker, which brings a host of its own, and the
|
|
19
|
+
* menu sits in a host sized to its button on both axes, as the date picker's pill does, so it drops into a row the way
|
|
20
|
+
* a `Text` does. Inside a `Screen` or `Island` either renders into that host instead (see `useInsideHost`): a host
|
|
21
|
+
* nested in the island's stack is given no height there, and the wheel spills over the views around it.
|
|
14
22
|
*/
|
|
15
|
-
export const Picker: PickerComponent = ({
|
|
23
|
+
export const Picker: PickerComponent = ({
|
|
24
|
+
disabled = false,
|
|
25
|
+
onValueChange,
|
|
26
|
+
options,
|
|
27
|
+
pickerStyle = 'wheel',
|
|
28
|
+
testID,
|
|
29
|
+
value,
|
|
30
|
+
}: PickerProps) => {
|
|
16
31
|
const theme = useAppTheme()
|
|
17
32
|
const insideHost = useInsideHost()
|
|
18
33
|
const color = theme.colorString('content.primary')
|
|
34
|
+
const menu = pickerStyle === 'menu'
|
|
19
35
|
|
|
20
36
|
const onChange = useCallback((next: string | number | null) => onValueChange?.(String(next)), [onValueChange])
|
|
21
|
-
const
|
|
22
|
-
() => [
|
|
23
|
-
|
|
37
|
+
const modifiers = useMemo(
|
|
38
|
+
() => [
|
|
39
|
+
pickerStyleModifier(pickerStyle),
|
|
40
|
+
...(menu ? [tint(theme.color('fill.accent.primary'))] : []),
|
|
41
|
+
...(disabled ? [disabledModifier(true)] : []),
|
|
42
|
+
],
|
|
43
|
+
[disabled, menu, pickerStyle, theme]
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const picker = (
|
|
47
|
+
<SwiftUIPicker modifiers={modifiers} onSelectionChange={onChange} selection={value} testID={testID}>
|
|
48
|
+
{options.map(option => (
|
|
49
|
+
<SwiftUIText key={option.value} modifiers={[tag(option.value), foregroundStyle(color)]}>
|
|
50
|
+
{option.label}
|
|
51
|
+
</SwiftUIText>
|
|
52
|
+
))}
|
|
53
|
+
</SwiftUIPicker>
|
|
24
54
|
)
|
|
25
55
|
|
|
26
56
|
if (insideHost) {
|
|
57
|
+
return picker
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (menu) {
|
|
27
61
|
return (
|
|
28
|
-
<
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
{option.label}
|
|
32
|
-
</SwiftUIText>
|
|
33
|
-
))}
|
|
34
|
-
</SwiftUIPicker>
|
|
62
|
+
<Host colorScheme={theme.dark ? 'dark' : 'light'} matchContents>
|
|
63
|
+
{picker}
|
|
64
|
+
</Host>
|
|
35
65
|
)
|
|
36
66
|
}
|
|
37
67
|
|
|
@@ -8,10 +8,13 @@ export type PickerOption = {
|
|
|
8
8
|
value: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** How SwiftUI shows the picker: a wheel, or a button that opens the options as a menu. */
|
|
12
|
+
export type PickerStyleName = 'menu' | 'wheel'
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
|
-
* A single choice from a list: a SwiftUI
|
|
13
|
-
* own host, so it renders outside `Screen` and `Island` as well. Inside one it
|
|
14
|
-
* can share a stack with other native views.
|
|
15
|
+
* A single choice from a list: a SwiftUI picker on iOS (a wheel, or a menu with `pickerStyle`), Material's exposed
|
|
16
|
+
* dropdown on Android. It brings its own host, so it renders outside `Screen` and `Island` as well. Inside one it
|
|
17
|
+
* renders into that host instead, so it can share a stack with other native views.
|
|
15
18
|
*/
|
|
16
19
|
export type PickerProps = {
|
|
17
20
|
/** Stops the user changing the selection, and dims the picker. */
|
|
@@ -20,6 +23,12 @@ export type PickerProps = {
|
|
|
20
23
|
onValueChange?: (value: string) => void
|
|
21
24
|
/** The choices, in order. */
|
|
22
25
|
options: PickerOption[]
|
|
26
|
+
/**
|
|
27
|
+
* SwiftUI's picker style. `wheel` by default: the options on a wheel, always in view. `menu` is a button with the
|
|
28
|
+
* selection, in the accent, that opens the options as a menu: what a screen with more than one picker, or a picker
|
|
29
|
+
* in a row, wants. iOS only. Android ignores it: its exposed dropdown is a menu already.
|
|
30
|
+
*/
|
|
31
|
+
pickerStyle?: PickerStyleName
|
|
23
32
|
/**
|
|
24
33
|
* Android: the dropdown field's test tag. iOS: the wheel's, inside a `Screen` or `Island` only; on its own,
|
|
25
34
|
* `@expo/ui`'s wheel picker drops it.
|