@bareboard/react-native 0.0.0-stage → 0.1.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/LICENSE +22 -0
- package/README.md +24 -2
- package/dist/components/button/button.d.ts +12 -0
- package/dist/components/button/button.js +10 -0
- package/dist/components/checkbox/checkbox.d.ts +5 -0
- package/dist/components/checkbox/checkbox.js +7 -0
- package/dist/components/close-button/close-button.d.ts +5 -0
- package/dist/components/close-button/close-button.js +14 -0
- package/dist/components/combobox/combobox-machine-glue.d.ts +6 -0
- package/dist/components/combobox/combobox-machine-glue.js +16 -0
- package/dist/components/combobox/combobox-machine.d.ts +143 -0
- package/dist/components/combobox/combobox-machine.js +377 -0
- package/dist/components/combobox/combobox.d.ts +66 -0
- package/dist/components/combobox/combobox.js +199 -0
- package/dist/components/data-interactive/data-interactive.d.ts +4 -0
- package/dist/components/data-interactive/data-interactive.js +8 -0
- package/dist/components/description/description.d.ts +4 -0
- package/dist/components/description/description.js +6 -0
- package/dist/components/dialog/dialog.d.ts +22 -0
- package/dist/components/dialog/dialog.js +27 -0
- package/dist/components/disclosure/disclosure.d.ts +35 -0
- package/dist/components/disclosure/disclosure.js +35 -0
- package/dist/components/field/field.d.ts +6 -0
- package/dist/components/field/field.js +9 -0
- package/dist/components/fieldset/fieldset.d.ts +3 -0
- package/dist/components/fieldset/fieldset.js +3 -0
- package/dist/components/focus-trap/focus-trap.d.ts +5 -0
- package/dist/components/focus-trap/focus-trap.js +5 -0
- package/dist/components/input/input.d.ts +6 -0
- package/dist/components/input/input.js +9 -0
- package/dist/components/label/label.d.ts +6 -0
- package/dist/components/label/label.js +9 -0
- package/dist/components/legend/legend.d.ts +6 -0
- package/dist/components/legend/legend.js +9 -0
- package/dist/components/listbox/listbox-machine-glue.d.ts +6 -0
- package/dist/components/listbox/listbox-machine-glue.js +16 -0
- package/dist/components/listbox/listbox-machine.d.ts +140 -0
- package/dist/components/listbox/listbox-machine.js +347 -0
- package/dist/components/listbox/listbox.d.ts +53 -0
- package/dist/components/listbox/listbox.js +91 -0
- package/dist/components/listbox-label/listbox-label.d.ts +2 -0
- package/dist/components/listbox-label/listbox-label.js +2 -0
- package/dist/components/listbox-selected-option/listbox-selected-option.d.ts +7 -0
- package/dist/components/listbox-selected-option/listbox-selected-option.js +16 -0
- package/dist/components/menu/menu-machine-glue.d.ts +6 -0
- package/dist/components/menu/menu-machine-glue.js +16 -0
- package/dist/components/menu/menu-machine.d.ts +109 -0
- package/dist/components/menu/menu-machine.js +238 -0
- package/dist/components/menu/menu.d.ts +34 -0
- package/dist/components/menu/menu.js +60 -0
- package/dist/components/menu-heading/menu-heading.d.ts +4 -0
- package/dist/components/menu-heading/menu-heading.js +6 -0
- package/dist/components/menu-section/menu-section.d.ts +4 -0
- package/dist/components/menu-section/menu-section.js +6 -0
- package/dist/components/menu-separator/menu-separator.d.ts +4 -0
- package/dist/components/menu-separator/menu-separator.js +6 -0
- package/dist/components/popover/popover-machine-glue.d.ts +6 -0
- package/dist/components/popover/popover-machine-glue.js +16 -0
- package/dist/components/popover/popover-machine.d.ts +30 -0
- package/dist/components/popover/popover-machine.js +49 -0
- package/dist/components/popover/popover.d.ts +25 -0
- package/dist/components/popover/popover.js +37 -0
- package/dist/components/popover-backdrop/popover-backdrop.d.ts +6 -0
- package/dist/components/popover-backdrop/popover-backdrop.js +14 -0
- package/dist/components/popover-group/popover-group.d.ts +4 -0
- package/dist/components/popover-group/popover-group.js +6 -0
- package/dist/components/popover-overlay/popover-overlay.d.ts +4 -0
- package/dist/components/popover-overlay/popover-overlay.js +6 -0
- package/dist/components/portal/portal.d.ts +9 -0
- package/dist/components/portal/portal.js +8 -0
- package/dist/components/radio-group/radio-group.d.ts +29 -0
- package/dist/components/radio-group/radio-group.js +36 -0
- package/dist/components/select/select.d.ts +7 -0
- package/dist/components/select/select.js +10 -0
- package/dist/components/switch/switch.d.ts +20 -0
- package/dist/components/switch/switch.js +24 -0
- package/dist/components/tab-panels/tab-panels.d.ts +4 -0
- package/dist/components/tab-panels/tab-panels.js +6 -0
- package/dist/components/tabs/tabs.d.ts +29 -0
- package/dist/components/tabs/tabs.js +40 -0
- package/dist/components/textarea/textarea.d.ts +5 -0
- package/dist/components/textarea/textarea.js +7 -0
- package/dist/components/transition/transition.d.ts +21 -0
- package/dist/components/transition/transition.js +34 -0
- package/dist/hooks/use-controllable.d.ts +1 -0
- package/dist/hooks/use-controllable.js +34 -0
- package/dist/hooks/use-event.d.ts +1 -0
- package/dist/hooks/use-event.js +8 -0
- package/dist/hooks/use-iso-morphic-effect.d.ts +2 -0
- package/dist/hooks/use-iso-morphic-effect.js +3 -0
- package/dist/hooks/use-latest-value.d.ts +1 -0
- package/dist/hooks/use-latest-value.js +9 -0
- package/dist/hooks/use-on-unmount.d.ts +1 -0
- package/dist/hooks/use-on-unmount.js +18 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +33 -0
- package/dist/internal/close-provider.d.ts +6 -0
- package/dist/internal/close-provider.js +9 -0
- package/dist/internal/disabled.d.ts +5 -0
- package/dist/internal/disabled.js +9 -0
- package/dist/internal/toggle.d.ts +17 -0
- package/dist/internal/toggle.js +17 -0
- package/dist/machine.d.ts +33 -0
- package/dist/machine.js +107 -0
- package/dist/machines/stack-machine.d.ts +32 -0
- package/dist/machines/stack-machine.js +51 -0
- package/dist/react-glue.d.ts +2 -0
- package/dist/react-glue.js +9 -0
- package/dist/utils/calculate-active-index.d.ts +25 -0
- package/dist/utils/calculate-active-index.js +74 -0
- package/dist/utils/default-map.d.ts +5 -0
- package/dist/utils/default-map.js +15 -0
- package/dist/utils/disposables.d.ts +31 -0
- package/dist/utils/disposables.js +68 -0
- package/dist/utils/find-active-index.d.ts +3 -0
- package/dist/utils/find-active-index.js +12 -0
- package/dist/utils/match.d.ts +1 -0
- package/dist/utils/match.js +12 -0
- package/dist/utils/micro-task.d.ts +1 -0
- package/dist/utils/micro-task.js +13 -0
- package/dist/utils/render.d.ts +3 -0
- package/dist/utils/render.js +4 -0
- package/dist/utils/sort-by-order.d.ts +16 -0
- package/dist/utils/sort-by-order.js +33 -0
- package/dist/utils/typeahead.d.ts +1 -0
- package/dist/utils/typeahead.js +11 -0
- package/package.json +43 -3
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type PressableProps, type StyleProp, type ViewStyle, type ViewInstance } from 'react-native';
|
|
3
|
+
export type PopoverBackdropProps = Omit<PressableProps, 'children' | 'style'> & {
|
|
4
|
+
style?: StyleProp<ViewStyle>;
|
|
5
|
+
};
|
|
6
|
+
export declare const PopoverBackdrop: ForwardRefExoticComponent<PopoverBackdropProps & RefAttributes<ViewInstance>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { Pressable, StyleSheet, } from 'react-native';
|
|
4
|
+
import { usePopoverMachineContext } from '../popover/popover-machine-glue';
|
|
5
|
+
// A press on the backdrop closes the popover, which replaces the web outside-click dismissal.
|
|
6
|
+
export const PopoverBackdrop = forwardRef(function PopoverBackdropFn(props, ref) {
|
|
7
|
+
let machine = usePopoverMachineContext('PopoverBackdrop');
|
|
8
|
+
let { onPress, style, ...theirProps } = props;
|
|
9
|
+
let handlePress = (event) => {
|
|
10
|
+
onPress?.(event);
|
|
11
|
+
machine.actions.close();
|
|
12
|
+
};
|
|
13
|
+
return (_jsx(Pressable, { ...theirProps, ref: ref, style: [StyleSheet.absoluteFill, style], onPress: handlePress }));
|
|
14
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type ViewProps, type ViewInstance } from 'react-native';
|
|
3
|
+
export type PopoverGroupProps = ViewProps;
|
|
4
|
+
export declare const PopoverGroup: ForwardRefExoticComponent<PopoverGroupProps & RefAttributes<ViewInstance>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type ViewProps, type ViewInstance } from 'react-native';
|
|
3
|
+
export type PopoverOverlayProps = ViewProps;
|
|
4
|
+
export declare const PopoverOverlay: ForwardRefExoticComponent<PopoverOverlayProps & RefAttributes<ViewInstance>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
|
+
export const PopoverOverlay = forwardRef(function PopoverOverlayFn(props, ref) {
|
|
5
|
+
return (_jsx(View, { ...props, ref: ref, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: [StyleSheet.absoluteFill, props.style] }));
|
|
6
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export type PortalProps = {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
};
|
|
5
|
+
export declare function Portal({ children }: PortalProps): import("react").JSX.Element;
|
|
6
|
+
export type PortalGroupProps = {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
export declare function PortalGroup({ children }: PortalGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import {} from 'react';
|
|
3
|
+
export function Portal({ children }) {
|
|
4
|
+
return _jsx(_Fragment, { children: children });
|
|
5
|
+
}
|
|
6
|
+
export function PortalGroup({ children }) {
|
|
7
|
+
return _jsx(_Fragment, { children: children });
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PressableProps, type ViewProps } from 'react-native';
|
|
3
|
+
import { type RenderChildren } from '../../utils/render';
|
|
4
|
+
import { Description } from '../description/description';
|
|
5
|
+
import { Label } from '../label/label';
|
|
6
|
+
export type RadioGroupProps<TValue> = Omit<ViewProps, 'children'> & {
|
|
7
|
+
value?: TValue;
|
|
8
|
+
defaultValue?: TValue;
|
|
9
|
+
onChange?: (value: TValue) => void;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
declare function RadioGroupRoot<TValue>({ value: controlledValue, defaultValue, onChange, disabled, children, ...theirProps }: RadioGroupProps<TValue>): import("react").JSX.Element;
|
|
14
|
+
export declare const RadioGroup: typeof RadioGroupRoot & {
|
|
15
|
+
Label: typeof Label;
|
|
16
|
+
Description: typeof Description;
|
|
17
|
+
};
|
|
18
|
+
export type RadioRenderPropArg = {
|
|
19
|
+
checked: boolean;
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
active: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type RadioProps<TValue> = Omit<PressableProps, 'children' | 'disabled'> & {
|
|
24
|
+
value: TValue;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
children?: RenderChildren<RadioRenderPropArg>;
|
|
27
|
+
};
|
|
28
|
+
export declare function Radio<TValue>({ value, disabled: radioDisabled, children, onPress, ...theirProps }: RadioProps<TValue>): import("react").JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
import { Pressable, View, } from 'react-native';
|
|
4
|
+
import { useControllable } from '../../hooks/use-controllable';
|
|
5
|
+
import { resolveChildren } from '../../utils/render';
|
|
6
|
+
import { Description } from '../description/description';
|
|
7
|
+
import { Label } from '../label/label';
|
|
8
|
+
let RadioGroupContext = createContext(null);
|
|
9
|
+
function useRadioGroupContext(componentName) {
|
|
10
|
+
let context = useContext(RadioGroupContext);
|
|
11
|
+
if (context === null) {
|
|
12
|
+
throw new Error(`<${componentName} /> must be rendered inside a <RadioGroup /> component.`);
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
function RadioGroupRoot({ value: controlledValue, defaultValue, onChange, disabled = false, children, ...theirProps }) {
|
|
17
|
+
let [value, select] = useControllable(controlledValue, onChange, defaultValue);
|
|
18
|
+
return (_jsx(RadioGroupContext.Provider, { value: { value, disabled, select }, children: _jsx(View, { ...theirProps, accessibilityRole: "radiogroup", children: children }) }));
|
|
19
|
+
}
|
|
20
|
+
export const RadioGroup = Object.assign(RadioGroupRoot, {
|
|
21
|
+
/** @deprecated use `<Label>` instead of `<RadioGroup.Label>` */
|
|
22
|
+
Label,
|
|
23
|
+
/** @deprecated use `<Description>` instead of `<RadioGroup.Description>` */
|
|
24
|
+
Description,
|
|
25
|
+
});
|
|
26
|
+
export function Radio({ value, disabled: radioDisabled = false, children, onPress, ...theirProps }) {
|
|
27
|
+
let group = useRadioGroupContext('Radio');
|
|
28
|
+
let checked = group.value === value;
|
|
29
|
+
let disabled = group.disabled || radioDisabled;
|
|
30
|
+
let handlePress = (event) => {
|
|
31
|
+
onPress?.(event);
|
|
32
|
+
if (!checked)
|
|
33
|
+
group.select(value);
|
|
34
|
+
};
|
|
35
|
+
return (_jsx(Pressable, { ...theirProps, disabled: disabled, accessibilityRole: "radio", accessibilityState: { ...theirProps.accessibilityState, checked, disabled }, onPress: handlePress, children: ({ pressed }) => resolveChildren(children, { checked, disabled, active: pressed }) }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Label } from '../label/label';
|
|
2
|
+
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '../listbox/listbox';
|
|
3
|
+
export declare const Select: typeof Listbox;
|
|
4
|
+
export declare const SelectButton: typeof ListboxButton;
|
|
5
|
+
export declare const SelectOptions: typeof ListboxOptions;
|
|
6
|
+
export declare const SelectOption: typeof ListboxOption;
|
|
7
|
+
export declare const SelectLabel: typeof Label;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Label } from '../label/label';
|
|
2
|
+
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '../listbox/listbox';
|
|
3
|
+
// The web Select wraps a native `<select>`, which React Native does not have. The Select here is the
|
|
4
|
+
// Listbox pattern: a button that shows the current value and a list of `SelectOption`s. Each option
|
|
5
|
+
// takes a `value`, and the `onChange` handler receives the value rather than a DOM event.
|
|
6
|
+
export const Select = Listbox;
|
|
7
|
+
export const SelectButton = ListboxButton;
|
|
8
|
+
export const SelectOptions = ListboxOptions;
|
|
9
|
+
export const SelectOption = ListboxOption;
|
|
10
|
+
export const SelectLabel = Label;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type ViewInstance } from 'react-native';
|
|
3
|
+
import { type ToggleProps } from '../../internal/toggle';
|
|
4
|
+
import { Description } from '../description/description';
|
|
5
|
+
import { Field } from '../field/field';
|
|
6
|
+
import { Label } from '../label/label';
|
|
7
|
+
export type SwitchProps = Omit<ToggleProps, 'role'>;
|
|
8
|
+
declare const SwitchRoot: ForwardRefExoticComponent<SwitchProps & RefAttributes<ViewInstance>>;
|
|
9
|
+
/** @deprecated use `<Field>` instead of `<Switch.Group>` */
|
|
10
|
+
export declare const SwitchGroup: typeof Field;
|
|
11
|
+
/** @deprecated use `<Label>` instead of `<Switch.Label>` */
|
|
12
|
+
export declare const SwitchLabel: typeof Label;
|
|
13
|
+
/** @deprecated use `<Description>` instead of `<Switch.Description>` */
|
|
14
|
+
export declare const SwitchDescription: typeof Description;
|
|
15
|
+
export declare const Switch: typeof SwitchRoot & {
|
|
16
|
+
Group: typeof SwitchGroup;
|
|
17
|
+
Label: typeof SwitchLabel;
|
|
18
|
+
Description: typeof SwitchDescription;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import {} from 'react-native';
|
|
4
|
+
import { Toggle } from '../../internal/toggle';
|
|
5
|
+
import { Description } from '../description/description';
|
|
6
|
+
import { Field } from '../field/field';
|
|
7
|
+
import { Label } from '../label/label';
|
|
8
|
+
const SwitchRoot = forwardRef(function SwitchFn(props, ref) {
|
|
9
|
+
return _jsx(Toggle, { ...props, ref: ref, role: "switch" });
|
|
10
|
+
});
|
|
11
|
+
/** @deprecated use `<Field>` instead of `<Switch.Group>` */
|
|
12
|
+
export const SwitchGroup = Field;
|
|
13
|
+
/** @deprecated use `<Label>` instead of `<Switch.Label>` */
|
|
14
|
+
export const SwitchLabel = Label;
|
|
15
|
+
/** @deprecated use `<Description>` instead of `<Switch.Description>` */
|
|
16
|
+
export const SwitchDescription = Description;
|
|
17
|
+
export const Switch = Object.assign(SwitchRoot, {
|
|
18
|
+
/** @deprecated use `<Field>` instead of `<Switch.Group>` */
|
|
19
|
+
Group: SwitchGroup,
|
|
20
|
+
/** @deprecated use `<Label>` instead of `<Switch.Label>` */
|
|
21
|
+
Label: SwitchLabel,
|
|
22
|
+
/** @deprecated use `<Description>` instead of `<Switch.Description>` */
|
|
23
|
+
Description: SwitchDescription,
|
|
24
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type ViewProps, type ViewInstance } from 'react-native';
|
|
3
|
+
export type TabPanelsProps = ViewProps;
|
|
4
|
+
export declare const TabPanels: ForwardRefExoticComponent<TabPanelsProps & RefAttributes<ViewInstance>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PressableProps, type ViewProps } from 'react-native';
|
|
2
|
+
import { type RenderChildren } from '../../utils/render';
|
|
3
|
+
export type TabGroupProps<TValue> = Omit<ViewProps, 'children'> & {
|
|
4
|
+
value?: TValue;
|
|
5
|
+
defaultValue?: TValue;
|
|
6
|
+
onChange?: (value: TValue) => void;
|
|
7
|
+
children?: RenderChildren<{
|
|
8
|
+
value: TValue | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
export declare function TabGroup<TValue>({ value: controlledValue, defaultValue, onChange, children, ...theirProps }: TabGroupProps<TValue>): import("react").JSX.Element;
|
|
12
|
+
export type TabListProps = ViewProps;
|
|
13
|
+
export declare function TabList(props: TabListProps): import("react").JSX.Element;
|
|
14
|
+
export type TabRenderPropArg = {
|
|
15
|
+
selected: boolean;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
active: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type TabProps<TValue> = Omit<PressableProps, 'children' | 'disabled'> & {
|
|
20
|
+
value: TValue;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
children?: RenderChildren<TabRenderPropArg>;
|
|
23
|
+
};
|
|
24
|
+
export declare function Tab<TValue>({ value, disabled: tabDisabled, children, onPress, ...theirProps }: TabProps<TValue>): import("react").JSX.Element;
|
|
25
|
+
export type TabPanelProps<TValue> = ViewProps & {
|
|
26
|
+
value: TValue;
|
|
27
|
+
unmount?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export declare function TabPanel<TValue>({ value, unmount, ...theirProps }: TabPanelProps<TValue>): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
import { Pressable, View, } from 'react-native';
|
|
4
|
+
import { useControllable } from '../../hooks/use-controllable';
|
|
5
|
+
import { useDisabled } from '../../internal/disabled';
|
|
6
|
+
import { resolveChildren } from '../../utils/render';
|
|
7
|
+
let TabGroupContext = createContext(null);
|
|
8
|
+
function useTabGroupContext(componentName) {
|
|
9
|
+
let context = useContext(TabGroupContext);
|
|
10
|
+
if (context === null) {
|
|
11
|
+
throw new Error(`<${componentName} /> must be rendered inside a <TabGroup /> component.`);
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
export function TabGroup({ value: controlledValue, defaultValue, onChange, children, ...theirProps }) {
|
|
16
|
+
let [value, select] = useControllable(controlledValue, onChange, defaultValue);
|
|
17
|
+
return (_jsx(TabGroupContext.Provider, { value: { value, select }, children: _jsx(View, { ...theirProps, children: resolveChildren(children, { value }) }) }));
|
|
18
|
+
}
|
|
19
|
+
export function TabList(props) {
|
|
20
|
+
return _jsx(View, { ...props, accessibilityRole: "tablist" });
|
|
21
|
+
}
|
|
22
|
+
export function Tab({ value, disabled: tabDisabled, children, onPress, ...theirProps }) {
|
|
23
|
+
let group = useTabGroupContext('Tab');
|
|
24
|
+
let providedDisabled = useDisabled();
|
|
25
|
+
let selected = group.value === value;
|
|
26
|
+
let disabled = tabDisabled ?? providedDisabled ?? false;
|
|
27
|
+
let handlePress = (event) => {
|
|
28
|
+
onPress?.(event);
|
|
29
|
+
if (!disabled)
|
|
30
|
+
group.select(value);
|
|
31
|
+
};
|
|
32
|
+
return (_jsx(Pressable, { ...theirProps, disabled: disabled, accessibilityRole: "tab", accessibilityState: { ...theirProps.accessibilityState, selected, disabled }, onPress: handlePress, children: ({ pressed }) => resolveChildren(children, { selected, disabled, active: pressed }) }));
|
|
33
|
+
}
|
|
34
|
+
export function TabPanel({ value, unmount = true, ...theirProps }) {
|
|
35
|
+
let group = useTabGroupContext('TabPanel');
|
|
36
|
+
let selected = group.value === value;
|
|
37
|
+
if (!selected && unmount)
|
|
38
|
+
return null;
|
|
39
|
+
return _jsx(View, { ...theirProps, style: [theirProps.style, !selected && { display: 'none' }] });
|
|
40
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type TextInputInstance } from 'react-native';
|
|
3
|
+
import { type InputProps } from '../input/input';
|
|
4
|
+
export type TextareaProps = Omit<InputProps, 'multiline'>;
|
|
5
|
+
export declare const Textarea: ForwardRefExoticComponent<TextareaProps & RefAttributes<TextInputInstance>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import {} from 'react-native';
|
|
4
|
+
import { Input } from '../input/input';
|
|
5
|
+
export const Textarea = forwardRef(function TextareaFn(props, ref) {
|
|
6
|
+
return _jsx(Input, { ...props, ref: ref, multiline: true });
|
|
7
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ViewProps } from 'react-native';
|
|
3
|
+
type TransitionTiming = {
|
|
4
|
+
unmount?: boolean;
|
|
5
|
+
enter?: number;
|
|
6
|
+
leave?: number;
|
|
7
|
+
};
|
|
8
|
+
type TransitionViewProps = ViewProps & TransitionTiming & {
|
|
9
|
+
show: boolean;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
export type TransitionRootProps = TransitionViewProps;
|
|
13
|
+
export declare function TransitionRoot({ show, ...theirProps }: TransitionRootProps): import("react").JSX.Element;
|
|
14
|
+
export type TransitionChildProps = Omit<TransitionViewProps, 'show'> & {
|
|
15
|
+
show?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function TransitionChild({ show, ...theirProps }: TransitionChildProps): import("react").JSX.Element;
|
|
18
|
+
export declare const Transition: typeof TransitionRoot & {
|
|
19
|
+
Child: typeof TransitionChild;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Animated } from 'react-native';
|
|
4
|
+
let TransitionContext = createContext(null);
|
|
5
|
+
// The web transition swaps CSS classes. Here the same lifecycle drives an opacity animation:
|
|
6
|
+
// `enter` and `leave` are durations in milliseconds, and the element unmounts after `leave`.
|
|
7
|
+
function TransitionView({ show, unmount = true, enter = 0, leave = 0, children, ...theirProps }) {
|
|
8
|
+
let [rendered, setRendered] = useState(show);
|
|
9
|
+
let opacity = useRef(new Animated.Value(show ? 1 : 0)).current;
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (show) {
|
|
12
|
+
setRendered(true);
|
|
13
|
+
Animated.timing(opacity, { toValue: 1, duration: enter, useNativeDriver: false }).start();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
Animated.timing(opacity, { toValue: 0, duration: leave, useNativeDriver: false }).start(({ finished }) => {
|
|
17
|
+
if (finished && unmount)
|
|
18
|
+
setRendered(false);
|
|
19
|
+
});
|
|
20
|
+
}, [show]);
|
|
21
|
+
if (!show && unmount && !rendered)
|
|
22
|
+
return null;
|
|
23
|
+
return (_jsx(Animated.View, { ...theirProps, style: [theirProps.style, { opacity }], children: children }));
|
|
24
|
+
}
|
|
25
|
+
export function TransitionRoot({ show, ...theirProps }) {
|
|
26
|
+
return (_jsx(TransitionContext.Provider, { value: show, children: _jsx(TransitionView, { ...theirProps, show: show }) }));
|
|
27
|
+
}
|
|
28
|
+
export function TransitionChild({ show, ...theirProps }) {
|
|
29
|
+
let inheritedShow = useContext(TransitionContext);
|
|
30
|
+
return _jsx(TransitionView, { ...theirProps, show: show ?? inheritedShow ?? true });
|
|
31
|
+
}
|
|
32
|
+
export const Transition = Object.assign(TransitionRoot, {
|
|
33
|
+
Child: TransitionChild,
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useControllable<T>(controlledValue: T | undefined, onChange?: (value: T) => void, defaultValue?: T): readonly [NonNullable<T>, (value: any) => void | undefined];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
import { useEvent } from './use-event';
|
|
3
|
+
export function useControllable(controlledValue, onChange, defaultValue) {
|
|
4
|
+
let [internalValue, setInternalValue] = useState(defaultValue);
|
|
5
|
+
let isControlled = controlledValue !== undefined;
|
|
6
|
+
let wasControlled = useRef(isControlled);
|
|
7
|
+
let didWarnOnUncontrolledToControlled = useRef(false);
|
|
8
|
+
let didWarnOnControlledToUncontrolled = useRef(false);
|
|
9
|
+
if (isControlled && !wasControlled.current && !didWarnOnUncontrolledToControlled.current) {
|
|
10
|
+
didWarnOnUncontrolledToControlled.current = true;
|
|
11
|
+
wasControlled.current = isControlled;
|
|
12
|
+
console.error('A component is changing from uncontrolled to controlled. This may be caused by the value changing from undefined to a defined value, which should not happen.');
|
|
13
|
+
}
|
|
14
|
+
else if (!isControlled && wasControlled.current && !didWarnOnControlledToUncontrolled.current) {
|
|
15
|
+
didWarnOnControlledToUncontrolled.current = true;
|
|
16
|
+
wasControlled.current = isControlled;
|
|
17
|
+
console.error('A component is changing from controlled to uncontrolled. This may be caused by the value changing from a defined value to undefined, which should not happen.');
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
(isControlled ? controlledValue : internalValue),
|
|
21
|
+
useEvent((value) => {
|
|
22
|
+
if (isControlled) {
|
|
23
|
+
return onChange?.(value);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// Ensure internal state is up to date with the value, before calling
|
|
27
|
+
// onChange. `flushSync` is not available in React Native, so the state
|
|
28
|
+
// update is simply scheduled before `onChange` runs.
|
|
29
|
+
setInternalValue(value);
|
|
30
|
+
return onChange?.(value);
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare let useEvent: <F extends (...args: any[]) => any, P extends any[] = Parameters<F>, R = ReturnType<F>>(cb: (...args: P) => R) => (...args: P) => R;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useLatestValue } from './use-latest-value';
|
|
3
|
+
export let useEvent =
|
|
4
|
+
// TODO: Add React.useEvent ?? once the useEvent hook is available
|
|
5
|
+
function useEvent(cb) {
|
|
6
|
+
let cache = useLatestValue(cb);
|
|
7
|
+
return React.useCallback((...args) => cache.current(...args), [cache]);
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLatestValue<T>(value: T): import("react").RefObject<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOnUnmount(cb: () => void): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { microTask } from '../utils/micro-task';
|
|
3
|
+
import { useEvent } from './use-event';
|
|
4
|
+
export function useOnUnmount(cb) {
|
|
5
|
+
let stableCb = useEvent(cb);
|
|
6
|
+
let trulyUnmounted = useRef(false);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
trulyUnmounted.current = false;
|
|
9
|
+
return () => {
|
|
10
|
+
trulyUnmounted.current = true;
|
|
11
|
+
microTask(() => {
|
|
12
|
+
if (!trulyUnmounted.current)
|
|
13
|
+
return;
|
|
14
|
+
stableCb();
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
}, [stableCb]);
|
|
18
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from './components/button/button';
|
|
2
|
+
export * from './components/checkbox/checkbox';
|
|
3
|
+
export * from './components/close-button/close-button';
|
|
4
|
+
export * from './components/combobox/combobox';
|
|
5
|
+
export * from './components/data-interactive/data-interactive';
|
|
6
|
+
export * from './components/description/description';
|
|
7
|
+
export * from './components/dialog/dialog';
|
|
8
|
+
export * from './components/disclosure/disclosure';
|
|
9
|
+
export * from './components/field/field';
|
|
10
|
+
export * from './components/fieldset/fieldset';
|
|
11
|
+
export * from './components/focus-trap/focus-trap';
|
|
12
|
+
export * from './components/input/input';
|
|
13
|
+
export * from './components/label/label';
|
|
14
|
+
export * from './components/legend/legend';
|
|
15
|
+
export * from './components/listbox-label/listbox-label';
|
|
16
|
+
export * from './components/listbox-selected-option/listbox-selected-option';
|
|
17
|
+
export * from './components/listbox/listbox';
|
|
18
|
+
export * from './components/menu-heading/menu-heading';
|
|
19
|
+
export * from './components/menu-section/menu-section';
|
|
20
|
+
export * from './components/menu-separator/menu-separator';
|
|
21
|
+
export * from './components/menu/menu';
|
|
22
|
+
export * from './components/popover-backdrop/popover-backdrop';
|
|
23
|
+
export * from './components/popover-group/popover-group';
|
|
24
|
+
export * from './components/popover-overlay/popover-overlay';
|
|
25
|
+
export * from './components/popover/popover';
|
|
26
|
+
export * from './components/portal/portal';
|
|
27
|
+
export * from './components/radio-group/radio-group';
|
|
28
|
+
export * from './components/select/select';
|
|
29
|
+
export * from './components/switch/switch';
|
|
30
|
+
export * from './components/tab-panels/tab-panels';
|
|
31
|
+
export * from './components/tabs/tabs';
|
|
32
|
+
export * from './components/textarea/textarea';
|
|
33
|
+
export * from './components/transition/transition';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from './components/button/button';
|
|
2
|
+
export * from './components/checkbox/checkbox';
|
|
3
|
+
export * from './components/close-button/close-button';
|
|
4
|
+
export * from './components/combobox/combobox';
|
|
5
|
+
export * from './components/data-interactive/data-interactive';
|
|
6
|
+
export * from './components/description/description';
|
|
7
|
+
export * from './components/dialog/dialog';
|
|
8
|
+
export * from './components/disclosure/disclosure';
|
|
9
|
+
export * from './components/field/field';
|
|
10
|
+
export * from './components/fieldset/fieldset';
|
|
11
|
+
export * from './components/focus-trap/focus-trap';
|
|
12
|
+
export * from './components/input/input';
|
|
13
|
+
export * from './components/label/label';
|
|
14
|
+
export * from './components/legend/legend';
|
|
15
|
+
export * from './components/listbox-label/listbox-label';
|
|
16
|
+
export * from './components/listbox-selected-option/listbox-selected-option';
|
|
17
|
+
export * from './components/listbox/listbox';
|
|
18
|
+
export * from './components/menu-heading/menu-heading';
|
|
19
|
+
export * from './components/menu-section/menu-section';
|
|
20
|
+
export * from './components/menu-separator/menu-separator';
|
|
21
|
+
export * from './components/menu/menu';
|
|
22
|
+
export * from './components/popover-backdrop/popover-backdrop';
|
|
23
|
+
export * from './components/popover-group/popover-group';
|
|
24
|
+
export * from './components/popover-overlay/popover-overlay';
|
|
25
|
+
export * from './components/popover/popover';
|
|
26
|
+
export * from './components/portal/portal';
|
|
27
|
+
export * from './components/radio-group/radio-group';
|
|
28
|
+
export * from './components/select/select';
|
|
29
|
+
export * from './components/switch/switch';
|
|
30
|
+
export * from './components/tab-panels/tab-panels';
|
|
31
|
+
export * from './components/tabs/tabs';
|
|
32
|
+
export * from './components/textarea/textarea';
|
|
33
|
+
export * from './components/transition/transition';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
let CloseContext = createContext(() => { });
|
|
4
|
+
export function useClose() {
|
|
5
|
+
return useContext(CloseContext);
|
|
6
|
+
}
|
|
7
|
+
export function CloseProvider({ value, children }) {
|
|
8
|
+
return _jsx(CloseContext.Provider, { value: value, children: children });
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext, useContext } from 'react';
|
|
3
|
+
let DisabledContext = createContext(undefined);
|
|
4
|
+
export function useDisabled() {
|
|
5
|
+
return useContext(DisabledContext);
|
|
6
|
+
}
|
|
7
|
+
export function DisabledProvider({ value, children, }) {
|
|
8
|
+
return _jsx(DisabledContext.Provider, { value: value, children: children });
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
|
+
import { type PressableProps, type ViewInstance } from 'react-native';
|
|
3
|
+
import { type RenderChildren } from '../utils/render';
|
|
4
|
+
export type ToggleRenderPropArg = {
|
|
5
|
+
checked: boolean;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
active: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type ToggleProps = Omit<PressableProps, 'children' | 'disabled'> & {
|
|
10
|
+
role: 'switch' | 'checkbox';
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
defaultChecked?: boolean;
|
|
13
|
+
onChange?: (checked: boolean) => void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
children?: RenderChildren<ToggleRenderPropArg>;
|
|
16
|
+
};
|
|
17
|
+
export declare const Toggle: ForwardRefExoticComponent<ToggleProps & RefAttributes<ViewInstance>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { Pressable, } from 'react-native';
|
|
4
|
+
import { useControllable } from '../hooks/use-controllable';
|
|
5
|
+
import { useEvent } from '../hooks/use-event';
|
|
6
|
+
import { resolveChildren } from '../utils/render';
|
|
7
|
+
import { useDisabled } from './disabled';
|
|
8
|
+
export const Toggle = forwardRef(function ToggleFn(props, ref) {
|
|
9
|
+
let providedDisabled = useDisabled();
|
|
10
|
+
let { role, checked: controlledChecked, defaultChecked, onChange: controlledOnChange, disabled = providedDisabled || false, children, onPress, ...theirProps } = props;
|
|
11
|
+
let [checked, onChange] = useControllable(controlledChecked, controlledOnChange, defaultChecked ?? false);
|
|
12
|
+
let handlePress = useEvent((event) => {
|
|
13
|
+
onPress?.(event);
|
|
14
|
+
onChange(!checked);
|
|
15
|
+
});
|
|
16
|
+
return (_jsx(Pressable, { ...theirProps, ref: ref, disabled: disabled, accessibilityRole: role, accessibilityState: { ...theirProps.accessibilityState, checked, disabled }, onPress: handlePress, children: ({ pressed }) => resolveChildren(children, { checked, disabled, active: pressed }) }));
|
|
17
|
+
});
|