@vellira-ui/react-native 2.90.15 → 2.91.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/index.d.ts +5 -0
- package/dist/index.js +170 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export type { AccordionProps } from './components/Accordion';
|
|
2
|
+
export type { AccordionItemProps } from './components/Accordion';
|
|
3
|
+
export type { AccordionTriggerProps } from './components/Accordion';
|
|
4
|
+
export type { AccordionContentProps } from './components/Accordion';
|
|
5
|
+
export { Accordion } from './components/Accordion';
|
|
1
6
|
export { Dropdown } from './components/Dropdown';
|
|
2
7
|
export type { DropdownContentProps, DropdownEmptyProps, DropdownGroupProps, DropdownItemProps, DropdownLabelProps, DropdownPresentation, DropdownProps, DropdownSelectEvent, DropdownSeparatorProps, DropdownTriggerProps, } from './components/Dropdown/types';
|
|
3
8
|
export type { ModalBodyProps, ModalCloseProps, ModalContentProps, ModalDescriptionProps, ModalFooterProps, ModalHeaderProps, ModalOverlayProps, ModalProps, ModalTitleProps, ModalTriggerProps, } from './components/Modal';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Children, cloneElement, createContext, createElement, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
-
import { Check, ChevronDown, Close, Search } from "@vellira-ui/icons";
|
|
3
1
|
import { AccessibilityInfo, ActivityIndicator, Animated, BackHandler, Dimensions, Easing, FlatList, Modal as Modal$1, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View, findNodeHandle, useWindowDimensions } from "react-native";
|
|
2
|
+
import { Children, cloneElement, createContext, createElement, forwardRef, isValidElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
3
|
import { createConsoleOverlayDiagnostics, createOverlayManagerStore, createOverlayZIndexPolicy, createRetainedResourceRegistry, deferOverlayFocusRestore, getCompoundSlot, markCompoundSlot, resolveOverlayPresentation } from "@vellira-ui/core";
|
|
5
4
|
import { controlSizes, darkTheme, highContrastTheme, lightTheme } from "@vellira-ui/tokens";
|
|
6
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { Check, ChevronDown, Close, Search } from "@vellira-ui/icons";
|
|
7
7
|
//#region src/theme/fontWeight.ts
|
|
8
8
|
const nativeFontWeights = /* @__PURE__ */ new Set([
|
|
9
9
|
"normal",
|
|
@@ -739,6 +739,173 @@ function useThemeStyles(createStyles) {
|
|
|
739
739
|
return useMemo(() => createStyles(theme), [createStyles, theme]);
|
|
740
740
|
}
|
|
741
741
|
//#endregion
|
|
742
|
+
//#region src/components/Accordion/Accordion.styles.ts
|
|
743
|
+
const createStyles$23 = (theme) => StyleSheet.create({
|
|
744
|
+
root: {
|
|
745
|
+
width: "100%",
|
|
746
|
+
overflow: "hidden",
|
|
747
|
+
borderWidth: 1,
|
|
748
|
+
borderColor: theme.semantic.border.muted,
|
|
749
|
+
borderRadius: theme.tokens.radius.lg,
|
|
750
|
+
backgroundColor: theme.semantic.surface.default
|
|
751
|
+
},
|
|
752
|
+
rootDisabled: { opacity: .7 },
|
|
753
|
+
item: {
|
|
754
|
+
borderBottomWidth: 1,
|
|
755
|
+
borderBottomColor: theme.semantic.border.muted
|
|
756
|
+
},
|
|
757
|
+
trigger: {
|
|
758
|
+
minHeight: theme.tokens.spacing[10],
|
|
759
|
+
justifyContent: "center",
|
|
760
|
+
paddingHorizontal: theme.tokens.spacing[4],
|
|
761
|
+
paddingVertical: theme.tokens.spacing[3],
|
|
762
|
+
backgroundColor: theme.semantic.surface.default
|
|
763
|
+
},
|
|
764
|
+
triggerExpanded: { backgroundColor: theme.semantic.surface.subtle },
|
|
765
|
+
triggerPressed: { backgroundColor: theme.semantic.surface.muted },
|
|
766
|
+
triggerDisabled: { backgroundColor: theme.semantic.surface.subtle },
|
|
767
|
+
triggerContent: {
|
|
768
|
+
flexDirection: "row",
|
|
769
|
+
alignItems: "center",
|
|
770
|
+
justifyContent: "space-between",
|
|
771
|
+
gap: theme.tokens.spacing[3]
|
|
772
|
+
},
|
|
773
|
+
triggerText: {
|
|
774
|
+
flex: 1,
|
|
775
|
+
color: theme.semantic.text.primary,
|
|
776
|
+
fontSize: theme.tokens.typography.size.md,
|
|
777
|
+
fontWeight: theme.tokens.typography.weight.medium,
|
|
778
|
+
lineHeight: theme.tokens.typography.lineHeight.md
|
|
779
|
+
},
|
|
780
|
+
triggerTextDisabled: { color: theme.semantic.text.disabled },
|
|
781
|
+
indicator: {
|
|
782
|
+
width: theme.tokens.spacing[4],
|
|
783
|
+
height: theme.tokens.spacing[4],
|
|
784
|
+
alignItems: "center",
|
|
785
|
+
justifyContent: "center"
|
|
786
|
+
},
|
|
787
|
+
indicatorExpanded: { transform: [{ rotate: "180deg" }] },
|
|
788
|
+
content: {
|
|
789
|
+
padding: theme.tokens.spacing[4],
|
|
790
|
+
backgroundColor: theme.semantic.surface.subtle
|
|
791
|
+
},
|
|
792
|
+
contentHidden: { display: "none" }
|
|
793
|
+
});
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region src/components/Accordion/Content/AccordionContent.tsx
|
|
796
|
+
function AccordionContent({ children, forceMount = false, hidden = false }) {
|
|
797
|
+
const { theme } = useTheme();
|
|
798
|
+
const styles = createStyles$23(theme);
|
|
799
|
+
if (hidden && !forceMount) return null;
|
|
800
|
+
return /* @__PURE__ */ jsx(View, {
|
|
801
|
+
style: [styles.content, hidden && styles.contentHidden],
|
|
802
|
+
children
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
//#endregion
|
|
806
|
+
//#region src/components/Accordion/Item/AccordionItem.tsx
|
|
807
|
+
function AccordionItem({ children }) {
|
|
808
|
+
const { theme } = useTheme();
|
|
809
|
+
const styles = createStyles$23(theme);
|
|
810
|
+
return /* @__PURE__ */ jsx(View, {
|
|
811
|
+
style: styles.item,
|
|
812
|
+
children
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
//#endregion
|
|
816
|
+
//#region src/components/Accordion/Trigger/AccordionTrigger.tsx
|
|
817
|
+
function AccordionTrigger({ children, disabled = false, expanded = false, onActivate }) {
|
|
818
|
+
const { theme } = useTheme();
|
|
819
|
+
const styles = createStyles$23(theme);
|
|
820
|
+
return /* @__PURE__ */ jsx(Pressable, {
|
|
821
|
+
disabled,
|
|
822
|
+
accessibilityRole: "button",
|
|
823
|
+
accessibilityState: {
|
|
824
|
+
disabled,
|
|
825
|
+
expanded
|
|
826
|
+
},
|
|
827
|
+
accessibilityHint: expanded ? "Collapses this section" : "Expands this section",
|
|
828
|
+
onPress: onActivate,
|
|
829
|
+
style: ({ pressed }) => [
|
|
830
|
+
styles.trigger,
|
|
831
|
+
expanded && styles.triggerExpanded,
|
|
832
|
+
pressed && !disabled && styles.triggerPressed,
|
|
833
|
+
disabled && styles.triggerDisabled
|
|
834
|
+
],
|
|
835
|
+
children: /* @__PURE__ */ jsxs(View, {
|
|
836
|
+
style: styles.triggerContent,
|
|
837
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
838
|
+
style: [styles.triggerText, disabled && styles.triggerTextDisabled],
|
|
839
|
+
children
|
|
840
|
+
}), /* @__PURE__ */ jsx(View, {
|
|
841
|
+
style: [styles.indicator, expanded && styles.indicatorExpanded],
|
|
842
|
+
accessibilityElementsHidden: true,
|
|
843
|
+
importantForAccessibility: "no",
|
|
844
|
+
children: /* @__PURE__ */ jsx(ChevronDown, {
|
|
845
|
+
width: 16,
|
|
846
|
+
height: 16,
|
|
847
|
+
color: disabled ? theme.semantic.text.disabled : theme.semantic.text.secondary
|
|
848
|
+
})
|
|
849
|
+
})]
|
|
850
|
+
})
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region src/components/Accordion/Root/AccordionRoot.tsx
|
|
855
|
+
function AccordionRoot({ children, type = "single", value, defaultValue, onValueChange, collapsible = false, disabled = false }) {
|
|
856
|
+
const { theme } = useTheme();
|
|
857
|
+
const styles = createStyles$23(theme);
|
|
858
|
+
const isControlled = value !== void 0;
|
|
859
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue ?? (type === "multiple" ? [] : ""));
|
|
860
|
+
const selectedValues = (isControlled ? value : uncontrolledValue) ?? [];
|
|
861
|
+
const expandedValues = Array.isArray(selectedValues) ? selectedValues : selectedValues ? [selectedValues] : [];
|
|
862
|
+
const selectValue = useCallback((itemValue) => {
|
|
863
|
+
if (disabled) return;
|
|
864
|
+
const isExpanded = expandedValues.includes(itemValue);
|
|
865
|
+
const nextValues = type === "multiple" ? isExpanded ? expandedValues.filter((current) => current !== itemValue) : [...expandedValues, itemValue] : isExpanded ? collapsible ? [] : expandedValues : [itemValue];
|
|
866
|
+
const nextValue = type === "multiple" ? nextValues : nextValues[0] ?? "";
|
|
867
|
+
if (!isControlled) setUncontrolledValue(nextValue);
|
|
868
|
+
onValueChange?.(nextValue);
|
|
869
|
+
}, [
|
|
870
|
+
collapsible,
|
|
871
|
+
disabled,
|
|
872
|
+
expandedValues,
|
|
873
|
+
isControlled,
|
|
874
|
+
onValueChange,
|
|
875
|
+
type
|
|
876
|
+
]);
|
|
877
|
+
const enhanceItem = (node) => {
|
|
878
|
+
if (!isValidElement(node) || node.type !== AccordionItem) return node;
|
|
879
|
+
const item = node;
|
|
880
|
+
const itemDisabled = disabled || Boolean(item.props.disabled);
|
|
881
|
+
const expanded = expandedValues.includes(item.props.value);
|
|
882
|
+
const itemChildren = Children.map(item.props.children, (child) => {
|
|
883
|
+
if (!isValidElement(child)) return child;
|
|
884
|
+
if (child.type === AccordionTrigger) return cloneElement(child, {
|
|
885
|
+
disabled: itemDisabled,
|
|
886
|
+
expanded,
|
|
887
|
+
onActivate: itemDisabled ? void 0 : () => selectValue(item.props.value)
|
|
888
|
+
});
|
|
889
|
+
if (child.type === AccordionContent) return cloneElement(child, { hidden: !expanded });
|
|
890
|
+
return child;
|
|
891
|
+
});
|
|
892
|
+
return cloneElement(item, { children: itemChildren });
|
|
893
|
+
};
|
|
894
|
+
return /* @__PURE__ */ jsx(View, {
|
|
895
|
+
style: [styles.root, disabled && styles.rootDisabled],
|
|
896
|
+
accessibilityState: { disabled },
|
|
897
|
+
children: Children.map(children, enhanceItem)
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/components/Accordion/Accordion.tsx
|
|
902
|
+
const Accordion = Object.assign(AccordionRoot, {
|
|
903
|
+
displayName: "Accordion",
|
|
904
|
+
Item: AccordionItem,
|
|
905
|
+
Trigger: AccordionTrigger,
|
|
906
|
+
Content: AccordionContent
|
|
907
|
+
});
|
|
908
|
+
//#endregion
|
|
742
909
|
//#region src/components/Dropdown/internal/DropdownContext.tsx
|
|
743
910
|
const DropdownContext = createContext(null);
|
|
744
911
|
const DropdownProvider = DropdownContext.Provider;
|
|
@@ -7123,4 +7290,4 @@ function Switch({ accessibilityLabel = "Switch", checked, defaultChecked = false
|
|
|
7123
7290
|
});
|
|
7124
7291
|
}
|
|
7125
7292
|
//#endregion
|
|
7126
|
-
export { Button, Checkbox, Dropdown, FormField, Input, Modal, Popover, Portal, PortalProvider, Radio, RadioGroup, Select, Switch, Tabs, ThemeProvider, Tooltip, nativeThemes, useTheme };
|
|
7293
|
+
export { Accordion, Button, Checkbox, Dropdown, FormField, Input, Modal, Popover, Portal, PortalProvider, Radio, RadioGroup, Select, Switch, Tabs, ThemeProvider, Tooltip, nativeThemes, useTheme };
|