@webority/mobile-ui 0.144.2 → 0.146.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/dist/canvas-kit/kit.js +4429 -3708
- package/dist/canvas-kit/manifest.json +1 -1
- package/dist/canvas-kit/release.json +5 -5
- package/lib/commonjs/components/Accordion/Accordion.js +1 -1
- package/lib/commonjs/components/AmountSlider/AmountSlider.js +1 -1
- package/lib/commonjs/components/AnimatePresence/AnimatePresence.js +1 -1
- package/lib/commonjs/components/AppBar/AppBar.js +1 -1
- package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
- package/lib/commonjs/components/AsyncBlock/AsyncBlock.js +1 -1
- package/lib/commonjs/components/AuthedImage/AuthedImage.js +1 -1
- package/lib/commonjs/components/Autocomplete/Autocomplete.js +1 -1
- package/lib/commonjs/components/Avatar/Avatar.js +1 -1
- package/lib/commonjs/components/Badge/Badge.js +1 -1
- package/lib/commonjs/components/Banner/Banner.js +1 -1
- package/lib/commonjs/components/BarChart/BarChart.js +1 -1
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Button/Button.js +1 -1
- package/lib/commonjs/components/Calendar/Calendar.js +1 -1
- package/lib/commonjs/components/Card/Card.js +1 -1
- package/lib/commonjs/components/Carousel/Carousel.js +1 -1
- package/lib/commonjs/components/Checkbox/Checkbox.js +1 -1
- package/lib/commonjs/components/Chip/Chip.js +1 -1
- package/lib/commonjs/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/commonjs/components/Confetti/Confetti.js +1 -1
- package/lib/commonjs/components/Descriptions/Descriptions.js +1 -1
- package/lib/commonjs/components/Dialog/Dialog.js +1 -1
- package/lib/commonjs/components/Dialog/OverlayActions.js +1 -1
- package/lib/commonjs/components/Divider/Divider.js +1 -1
- package/lib/commonjs/components/Drawer/Drawer.js +1 -1
- package/lib/commonjs/components/EmptyState/EmptyState.js +1 -1
- package/lib/commonjs/components/FieldBase/FieldBase.js +1 -1
- package/lib/commonjs/components/FilePicker/FilePicker.js +1 -1
- package/lib/commonjs/components/FileViewer/FileViewer.js +1 -1
- package/lib/commonjs/components/FilterChipRow/FilterChipRow.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/FormField/FormField.js +1 -1
- package/lib/commonjs/components/IconBadge/IconBadge.js +1 -1
- package/lib/commonjs/components/IconButton/IconButton.js +1 -1
- package/lib/commonjs/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/commonjs/components/Input/Input.js +1 -1
- package/lib/commonjs/components/ListItem/ListItem.js +1 -1
- package/lib/commonjs/components/ListSection/ListSection.js +1 -1
- package/lib/commonjs/components/Menu/Menu.js +1 -1
- package/lib/commonjs/components/Menu/useContextMenu.js +1 -1
- package/lib/commonjs/components/MessageBubble/MessageBubble.js +1 -1
- package/lib/commonjs/components/Modal/Modal.js +1 -1
- package/lib/commonjs/components/NumberInput/NumberInput.js +1 -1
- package/lib/commonjs/components/OTPInput/OTPInput.js +1 -1
- package/lib/commonjs/components/PermissionPrompt/PermissionPrompt.js +1 -1
- package/lib/commonjs/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/commonjs/components/PickerTrigger/PickerTrigger.js +1 -1
- package/lib/commonjs/components/ProfileCompletion/ProfileCompletion.js +1 -1
- package/lib/commonjs/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/commonjs/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/commonjs/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/commonjs/components/Radio/Radio.js +1 -1
- package/lib/commonjs/components/Rating/Rating.js +1 -1
- package/lib/commonjs/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/commonjs/components/SearchBar/SearchBar.js +1 -1
- package/lib/commonjs/components/SectionHeader/SectionHeader.js +1 -1
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/commonjs/components/Select/Select.js +1 -1
- package/lib/commonjs/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/commonjs/components/Skeleton/Skeleton.js +1 -1
- package/lib/commonjs/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/commonjs/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/commonjs/components/Slider/Slider.js +1 -1
- package/lib/commonjs/components/SliderField/SliderField.js +1 -1
- package/lib/commonjs/components/Sparkline/Sparkline.js +1 -1
- package/lib/commonjs/components/Spinner/Spinner.js +1 -1
- package/lib/commonjs/components/StatTile/StatTile.js +1 -1
- package/lib/commonjs/components/StatusBadge/StatusBadge.js +1 -1
- package/lib/commonjs/components/Stepper/Stepper.js +1 -1
- package/lib/commonjs/components/Swipeable/Swipeable.js +1 -1
- package/lib/commonjs/components/Switch/Switch.js +1 -1
- package/lib/commonjs/components/Tabs/Tabs.js +1 -1
- package/lib/commonjs/components/TagInput/TagInput.js +1 -1
- package/lib/commonjs/components/Text/Text.js +1 -1
- package/lib/commonjs/components/TimePicker/TimePicker.js +1 -1
- package/lib/commonjs/components/Timeline/Timeline.js +1 -1
- package/lib/commonjs/components/Toast/Toast.js +1 -1
- package/lib/commonjs/components/Tooltip/Tooltip.js +1 -1
- package/lib/commonjs/components/WheelPicker/WheelPicker.js +1 -1
- package/lib/commonjs/utils/assertValidValue.js +1 -0
- package/lib/module/components/Accordion/Accordion.js +1 -1
- package/lib/module/components/AmountSlider/AmountSlider.js +1 -1
- package/lib/module/components/AnimatePresence/AnimatePresence.js +1 -1
- package/lib/module/components/AppBar/AppBar.js +1 -1
- package/lib/module/components/AppIcon/AppIcon.js +1 -1
- package/lib/module/components/AsyncBlock/AsyncBlock.js +1 -1
- package/lib/module/components/AuthedImage/AuthedImage.js +1 -1
- package/lib/module/components/Autocomplete/Autocomplete.js +1 -1
- package/lib/module/components/Avatar/Avatar.js +1 -1
- package/lib/module/components/Badge/Badge.js +1 -1
- package/lib/module/components/Banner/Banner.js +1 -1
- package/lib/module/components/BarChart/BarChart.js +1 -1
- package/lib/module/components/BottomNavigation/BottomNavigation.js +1 -1
- package/lib/module/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/module/components/Button/Button.js +1 -1
- package/lib/module/components/Calendar/Calendar.js +1 -1
- package/lib/module/components/Card/Card.js +1 -1
- package/lib/module/components/Carousel/Carousel.js +1 -1
- package/lib/module/components/Checkbox/Checkbox.js +1 -1
- package/lib/module/components/Chip/Chip.js +1 -1
- package/lib/module/components/ChoiceGroup/ChoiceGroup.js +1 -1
- package/lib/module/components/Confetti/Confetti.js +1 -1
- package/lib/module/components/Descriptions/Descriptions.js +1 -1
- package/lib/module/components/Dialog/Dialog.js +1 -1
- package/lib/module/components/Dialog/OverlayActions.js +1 -1
- package/lib/module/components/Divider/Divider.js +1 -1
- package/lib/module/components/Drawer/Drawer.js +1 -1
- package/lib/module/components/EmptyState/EmptyState.js +1 -1
- package/lib/module/components/FieldBase/FieldBase.js +1 -1
- package/lib/module/components/FilePicker/FilePicker.js +1 -1
- package/lib/module/components/FileViewer/FileViewer.js +1 -1
- package/lib/module/components/FilterChipRow/FilterChipRow.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/FormField/FormField.js +1 -1
- package/lib/module/components/IconBadge/IconBadge.js +1 -1
- package/lib/module/components/IconButton/IconButton.js +1 -1
- package/lib/module/components/InlineSelect/InlineSelect.js +1 -1
- package/lib/module/components/Input/Input.js +1 -1
- package/lib/module/components/ListItem/ListItem.js +1 -1
- package/lib/module/components/ListSection/ListSection.js +1 -1
- package/lib/module/components/Menu/Menu.js +1 -1
- package/lib/module/components/Menu/useContextMenu.js +1 -1
- package/lib/module/components/MessageBubble/MessageBubble.js +1 -1
- package/lib/module/components/Modal/Modal.js +1 -1
- package/lib/module/components/NumberInput/NumberInput.js +1 -1
- package/lib/module/components/OTPInput/OTPInput.js +1 -1
- package/lib/module/components/PermissionPrompt/PermissionPrompt.js +1 -1
- package/lib/module/components/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/lib/module/components/PickerTrigger/PickerTrigger.js +1 -1
- package/lib/module/components/ProfileCompletion/ProfileCompletion.js +1 -1
- package/lib/module/components/ProfilePicker/ProfilePicker.js +1 -1
- package/lib/module/components/ProgressBar/ProgressBar.js +1 -1
- package/lib/module/components/ProgressRing/ProgressRing.js +1 -1
- package/lib/module/components/Radio/Radio.js +1 -1
- package/lib/module/components/Rating/Rating.js +1 -1
- package/lib/module/components/ScannerOverlay/ScannerOverlay.js +1 -1
- package/lib/module/components/SearchBar/SearchBar.js +1 -1
- package/lib/module/components/SectionHeader/SectionHeader.js +1 -1
- package/lib/module/components/SegmentedControl/SegmentedControl.js +1 -1
- package/lib/module/components/Select/Select.js +1 -1
- package/lib/module/components/SignaturePad/SignaturePad.js +1 -1
- package/lib/module/components/Skeleton/Skeleton.js +1 -1
- package/lib/module/components/Skeleton/SkeletonContent.js +1 -1
- package/lib/module/components/SlideToConfirm/SlideToConfirm.js +1 -1
- package/lib/module/components/Slider/Slider.js +1 -1
- package/lib/module/components/SliderField/SliderField.js +1 -1
- package/lib/module/components/Sparkline/Sparkline.js +1 -1
- package/lib/module/components/Spinner/Spinner.js +1 -1
- package/lib/module/components/StatTile/StatTile.js +1 -1
- package/lib/module/components/StatusBadge/StatusBadge.js +1 -1
- package/lib/module/components/Stepper/Stepper.js +1 -1
- package/lib/module/components/Swipeable/Swipeable.js +1 -1
- package/lib/module/components/Switch/Switch.js +1 -1
- package/lib/module/components/Tabs/Tabs.js +1 -1
- package/lib/module/components/TagInput/TagInput.js +1 -1
- package/lib/module/components/Text/Text.js +1 -1
- package/lib/module/components/TimePicker/TimePicker.js +1 -1
- package/lib/module/components/Timeline/Timeline.js +1 -1
- package/lib/module/components/Toast/Toast.js +1 -1
- package/lib/module/components/Tooltip/Tooltip.js +1 -1
- package/lib/module/components/WheelPicker/WheelPicker.js +1 -1
- package/lib/module/utils/assertValidValue.js +1 -0
- package/lib/typescript/commonjs/utils/assertValidValue.d.ts +10 -0
- package/lib/typescript/module/utils/assertValidValue.d.ts +10 -0
- package/package.json +7 -7
- package/lib/commonjs/utils/warnInvalidValue.js +0 -1
- package/lib/module/utils/warnInvalidValue.js +0 -1
- package/lib/typescript/commonjs/utils/warnInvalidValue.d.ts +0 -10
- package/lib/typescript/module/utils/warnInvalidValue.d.ts +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{useDebounce}from"../../hooks/useDebounce.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/useControllableState.js";import{useDebounce}from"../../hooks/useDebounce.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{mergeRefs}from"../../utils/mergeRefs.js";import{defaultIcons}from"../AppIcon/defaultIcons.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldBase,FieldLabel,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{useFloatingLabel}from"../FieldBase/useFloatingLabel.js";import{normalizeSuggestion,SearchRecents,SearchScopeBar,SearchSuggestions}from"./SearchPanel.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SEARCH_BAR_LABELS=Object.freeze({placeholder:"Search…",recents:"Recent searches",clearAll:"Clear all",clearAllRecents:"Clear all recent searches",searchAgain:"Searches again",removeRecent:e=>`Remove ${e} from recent searches`,scope:"Search scope",clearSearch:"Clear search",searching:e=>`Searching ${e}`,suggestionCount:e=>1===e?"1 suggestion":`${e} suggestions`,removed:e=>`Removed ${e}`,recentsCleared:"Recent searches cleared"});const DEFAULT_PANEL_ROWS=8,HOLD_RELEASE_MS=50,SearchBar=forwardRef((e,s)=>{const{value:l,onChangeText:a,onSubmit:t,onFocus:o,onBlur:r,placeholder:i,autoFocus:n=!1,disabled:c=!1,onClear:u,leftIcon:d,debounceMs:p,size:h="md",variant:b,radius:m,label:f,labelMode:S="top",labelStyle:g,scopes:v,scope:C,onScopeChange:x,recents:R,maxRecents:j=DEFAULT_PANEL_ROWS,onSelectRecent:y,onRemove:F,onClearRecents:_,suggestions:L,maxSuggestions:k=DEFAULT_PANEL_ROWS,onSelect:B,haptic:E,labels:A,style:V,inputStyle:T,accessibilityLabel:z,testID:I,...H}=e;assertValidValue("SearchBar","size",e.size,["sm","md","lg"]),assertValidValue("SearchBar","variant",e.variant,["outline","filled","underline"]),assertValidValue("SearchBar","labelMode",e.labelMode,["top","float"]);const M=useTheme(),w=useMemo(()=>({...DEFAULT_SEARCH_BAR_LABELS,...A}),[A]),D=i??w.placeholder,P=b??M.settings.components["search-bar"]?.defaultVariant??M.settings.components.field?.defaultVariant??"filled",O="underline"===P,N=resolveFieldSize(M,h),U=m??M.components["search-bar"][h].radius,W=resolveFieldTextStyle(M,{disabled:c}),$=useRef(null),q=useMemo(()=>mergeRefs($,s),[s]),K=useCallback(()=>{c||$.current?.focus()},[c]),G=useMemo(()=>buildStyles(M),[M]),J="string"==typeof l?l:"",[Q,X]=useState(!1),Y=useCallback(e=>{X(!0),o?.(e)},[o]),Z=useCallback(e=>{X(!1),r?.(e)},[r]),[ee,se]=useState(J),le=useDebounce(ee,p??0);useEffect(()=>{void 0!==p&&J!==ee&&se(J)},[J,p]);const ae=useRef(J);useEffect(()=>{void 0!==p&&le!==ae.current&&(ae.current=le,a(le))},[le,p,a]);const te=useCallback(e=>{void 0===p?a(e):se(e)},[p,a]),oe=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e),void 0!==p&&(se(""),ae.current=""),a(""),u?.()},[E,p,a,u]),re=useCallback(()=>{t?.(void 0!==p?ee:J)},[t,p,ee,J]),ie=void 0!==p?ee:J,ne=ie.length>0,[ce,ue]=useControllableState({value:C,defaultValue:v?.[0]?.value??"",onChange:x}),de=useCallback(e=>{ue(e);const s=v?.find(s=>s.value===e)?.label;s&&announce(w.searching(s))},[v,ue,w]),[pe,he]=useState(!1),be=useRef(null),me=useCallback(()=>{be.current&&(clearTimeout(be.current),be.current=null)},[]),fe=useCallback(()=>{me(),he(!0)},[me]),Se=useCallback(()=>{me(),be.current=setTimeout(()=>he(!1),50)},[me]);useEffect(()=>me,[me]);const ge=!c&&(Q||pe),ve=useMemo(()=>(R??[]).slice(0,j),[R,j]),Ce=useMemo(()=>(L??[]).slice(0,k).map(normalizeSuggestion),[L,k]),xe=ge&&!ne&&ve.length>0,Re=ge&&ne&&Ce.length>0,je=Re?Ce.length:0,ye=je>0?w.suggestionCount(je):"";useEffect(()=>{ye&&announce(ye)},[ye]);const Fe=useCallback(()=>{const e=resolveHaptic(E,"selection");e&&triggerHaptic(e)},[E]),Le=useCallback(e=>{Fe(),$.current?.blur(),he(!1),y?.(e)},[Fe,y]),ke=useCallback(e=>{Fe(),$.current?.blur(),he(!1),B?.(e)},[Fe,B]),Be=useCallback(e=>{Fe(),F?.(e),announce(w.removed(e)),K()},[Fe,F,K,w]),Ee=useCallback(()=>{Fe(),_?.(),announce(w.recentsCleared),K()},[Fe,_,K,w]),Ae={size:N.icon,color:c?M.colors["text-disabled"]:M.colors["text-subtle"],disabled:c},Ve=d?renderSlotIcon(d,Ae):(M.settings.icons.search??defaultIcons.search)(Ae),Te=_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:Ve}),ze=Boolean(f)&&"float"===S,Ie=useFloatingLabel({label:f,enabled:ze,floated:Q||ne,variant:P,sizeTokens:N,leadingOffset:N.icon+M.space.md,trailingOffset:ne?N.icon+M.space.md:0,paddingLeft:O?M.space.none:N["padding-x"],color:M.colors["field-label"],style:g}),He=ne&&!c?_jsx(Pressable,{onPress:oe,hitSlop:8,...hitSlopMarker(8),accessibilityRole:"button",accessibilityLabel:w.clearSearch,children:(M.settings.icons.close??defaultIcons.close)({size:N.icon,color:M.colors["text-muted"]})}):null;return _jsxs(View,{style:V,testID:I,children:[f&&!ze?_jsx(FieldLabel,{size:h,style:g,children:f}):null,_jsx(View,{style:G.root,children:_jsxs(View,{style:G.fieldWrap,children:[_jsx(FieldBase,{size:h,variant:P,focused:Q,disabled:c,filled:ne,minHeight:N["min-height"],paddingHorizontal:O?M.space.none:N["padding-x"],radius:U,leading:Te,trailing:He,topNotch:Ie.topNotch,onPress:K,pressFeedback:!1,accessibilityRole:"search",accessibilityLabel:z??D,children:_jsx(TextInput,{ref:q,style:[G.input,{fontSize:N.text,color:W.color,...W.weightStyle},T],value:ie,onChangeText:te,onSubmitEditing:re,onFocus:Y,onBlur:Z,placeholder:!ze||Q||ne?D:void 0,placeholderTextColor:W.placeholderColor,autoFocus:n,editable:!c,returnKeyType:"search",selectionColor:resolveVariantColors(M,P).borderFocusedRepresentative,accessibilityLabel:z??D,accessibilityState:{disabled:c},"aria-disabled":c,...H})}),Ie.node]})}),v&&v.length>0?_jsx(SearchScopeBar,{scopes:v,scope:ce||(v[0]?.value??""),disabled:c,haptic:E,labels:w,onChange:de}):null,xe?_jsx(SearchRecents,{recents:ve,labels:w,onSelect:Le,onRemove:F?Be:void 0,onClear:_?Ee:void 0,onHold:fe,onRelease:Se}):null,Re?_jsx(SearchSuggestions,{suggestions:Ce,query:ie,onSelect:ke,onHold:fe,onRelease:Se}):null]})});SearchBar.displayName="SearchBar";const buildStyles=e=>StyleSheet.create({root:{flexDirection:"row",alignItems:"center",width:"100%",position:"relative",overflow:"visible"},fieldWrap:{flex:1,position:"relative",overflow:"visible"},input:{flex:1,padding:e.space.none,margin:e.space.none,includeFontPadding:!1}});export{SearchBar};export default SearchBar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useMemo}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{useMemo}from"react";import{View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Button}from"../Button/index.js";import{RequiredMark}from"../FieldBase/index.js";import{Text}from"../Text/Text.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SECTION_HEADER_LABELS=Object.freeze({required:e=>`${e}, required`});export const SectionHeader=e=>{const{children:t,variant:s,flush:r,flushBottom:i=!1,required:a=!1,action:o,labels:l,style:n,testID:m}=e;assertValidValue("SectionHeader","variant",e.variant,["title","caps","sub"]);const c=useTheme(),u=c.settings.components["section-header"],d=s??u?.defaultVariant??"title",p=r??u?.defaultFlush??!1,x=useMemo(()=>({...DEFAULT_SECTION_HEADER_LABELS,...l}),[l]),f=useMemo(()=>({marginTop:p?0:c.space.lg,marginBottom:i?0:c.space.sm}),[c,p,i]),h=useMemo(()=>({flexDirection:"row",alignItems:"center",justifyContent:"space-between",gap:c.space.sm}),[c]),j=useMemo(()=>({flex:1}),[]),v="caps"===d?{variant:"overline",color:"tertiary",weight:void 0}:"sub"===d?{variant:"label",color:"primary",weight:"semibold"}:{variant:"title",color:void 0,weight:void 0},b=_jsxs(Text,{variant:v.variant,color:v.color,weight:v.weight,accessibilityRole:"header",accessibilityLabel:a&&"string"==typeof t?x.required(t):void 0,style:o?j:[f,n],testID:m,children:[t,a?_jsx(RequiredMark,{}):null]});return o?_jsxs(View,{style:[h,f,n],children:[b,_jsx(Button,{variant:"link",size:"sm",label:o.label,onPress:o.onPress,testID:o.testID})]}):b};export default SectionHeader;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,resolveSegmentedControlSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{renderSlotIcon}from"../AppIcon/slotIcon.js";import{FieldLabel,FieldMessage,hasFieldText}from"../FieldBase/index.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const LABEL_LINE_HEIGHT_RATIO=1.25,activeInkFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"neutral":return e.colors["text-body"];case"success":return e.colors["success-text"];case"warning":return e.colors["warning-text"];case"danger":return e.colors["danger-text"];default:return e.colors["info-text"]}},SegmentedControl=forwardRef((e,t)=>{const{segments:s,label:r,helperText:i,error:l,value:o,defaultValue:n,onChange:a,size:d="md",fullWidth:c=!0,disabled:u=!1,tone:m="primary",variant:h="segmented",radius:g,labelLines:p=1,haptic:f,accessibilityLabel:b,style:x,containerStyle:y,segmentStyle:S,selectedIndicatorStyle:v,textStyle:w,labelStyle:C,testID:j}=e;assertValidValue("SegmentedControl","size",e.size,["sm","md","lg"]),assertValidValue("SegmentedControl","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SegmentedControl","variant",e.variant,["underline","pills","segmented"]);const[V,k]=useControllableState({value:o,defaultValue:n??s[0]?.value,onChange:a}),F=useTheme(),I=F.components["segmented-control"],L=useMemo(()=>buildStyles(F),[F]),_=useMemo(()=>resolveSegmentedControlSize(F,d),[F,d]),z=p>=2?2:1,M=z>1,R="segmented"===h,T="underline"===h,A="pills"===h,E=R?F.space[I["track-padding"]]:0,H=Math.ceil(1.25*_.text)*(z-1),q=I["underline-height"],D=F.space[I["pill-inset"]],B="number"==typeof g?g:g?F.radius[g]:void 0,W=B??F.radius.md,P=void 0===B?F.radius.sm:Math.max(B-E,0),N=B??F.radius.pill,G=B??F.radius.none,[O,X]=useState([]),J=useRef(createAnimatedValue(0)).current,K=Math.max(0,s.findIndex(e=>e.value===V)),Q=O[K],U=Q?.x,Y=useCallback(e=>{const t=F.motion.spring.snappy,s=Animated.spring(J,{toValue:e,damping:t.damping,stiffness:t.stiffness,mass:t.mass,overshootClamping:!0,useNativeDriver:!0});return s.start(),s},[F.motion.spring.snappy,J]);useEffect(()=>{X(e=>e.length===s.length||0===e.length?e:[])},[s.length]);const Z=useRef(null);useEffect(()=>{if(void 0===U)return;const e=null!==Z.current&&Z.current!==K;if(Z.current=K,!e)return void J.setValue(U);const t=Y(U);return()=>t.stop()},[K,U,Y,J]);const $=useCallback((e,t)=>{const{x:s,width:r}=t.nativeEvent.layout;X(t=>{const i=t[e];if(i&&i.x===s&&i.width===r)return t;const l=t.slice();return l[e]={x:s,width:r},l})},[]),ee=useCallback(e=>{if(u)return;if(e.value===V)return;const t=resolveHaptic(f,"selection");t&&triggerHaptic(t),k(e.value)},[u,k,V,f]),te=R?F.colors.thumb:A?F.colors["primary-soft"]:F.colors.primary,se=R?P:A?N:G,re=activeInkFor(F,m),ie=F.colors["bg-muted"],le=useSquircle(R,W),oe=!0===l||hasFieldText(l),ne=oe&&!u,ae=F.colors["field-border-error"],de=F.size.border,ce=hasFieldText(r),ue=oe?l:i,me=hasFieldText(ue),he=_jsxs(View,{ref:t,accessibilityRole:"radiogroup",accessibilityLabel:b??("string"==typeof r?r:void 0),testID:j,style:[L.track,{...M?{minHeight:_.height+H}:{height:_.height},opacity:u?.55:1,alignSelf:c?"stretch":"flex-start"},R?{borderRadius:W,...smoothCorners,backgroundColor:le.active?"transparent":ie,padding:E}:T?{borderBottomColor:ne?ae:F.colors["border-subtle"],borderBottomWidth:StyleSheet.hairlineWidth}:null,y,x],onLayout:le.onLayout,children:[le.active&&le.size?_jsx(SquircleFill,{width:le.size.width,height:le.size.height,radius:W,fill:ie,stroke:ne?ae:void 0,strokeWidth:de}):null,_jsxs(View,{style:L.row,children:[Q?_jsx(Animated.View,{pointerEvents:"none",style:[L.thumb,R?M?{top:0,bottom:0}:{top:0,height:_.height-2*E}:A?{top:D,bottom:D,left:D}:{bottom:0,height:q},{width:A?Math.max(Q.width-2*D,0):Q.width,borderRadius:se,...smoothCorners,backgroundColor:te,transform:[{translateX:J}]},v]}):null,s.map((e,t)=>{const s=e.value===V,r=s?re:F.colors["text-subtle"],i=renderSlotIcon(e.icon,{color:r,size:_.icon,selected:s,disabled:u});return _jsxs(Pressable,{onPress:()=>ee(e),onLayout:e=>$(t,e),disabled:u,accessibilityRole:"radio",accessibilityLabel:e.label,accessibilityState:{checked:s,selected:s,disabled:u},"aria-checked":s,"aria-disabled":u,style:({pressed:e})=>[L.segment,M?L.segmentMultiline:null,{paddingHorizontal:_["padding-x"],opacity:e&&!s?.7:1},S],children:[i?_jsx(View,{style:L.segmentIcon,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:i}):null,_jsx(Text,{variant:"label",weight:s?"semibold":"medium",style:[L.segmentLabel,M?L.segmentLabelMultiline:null,{color:r,fontSize:_.text},w,C],numberOfLines:z,children:e.label})]},String(e.value))})]}),!ne||T||le.active?null:_jsx(View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{borderWidth:de,borderColor:ae,borderRadius:R?W:N,...smoothCorners}]})]});return ce||me?_jsxs(View,{style:{alignSelf:c?"stretch":"flex-start"},children:[ce?_jsx(FieldLabel,{size:d,children:r}):null,he,me?_jsx(FieldMessage,{size:d,text:ue,error:oe}):null]}):he});SegmentedControl.displayName="SegmentedControl";const buildStyles=e=>StyleSheet.create({track:{flexDirection:"row",alignItems:"stretch",position:"relative"},row:{flex:1,flexDirection:"row",alignItems:"stretch",position:"relative",overflow:"hidden"},thumb:{position:"absolute",left:0},segment:{flexGrow:1,flexShrink:1,flexBasis:"auto",flexDirection:"row",alignItems:"center",justifyContent:"center"},segmentIcon:{marginRight:e.space.xs},segmentMultiline:{paddingVertical:e.space.xs},segmentLabel:{includeFontPadding:!1},segmentLabelMultiline:{flexShrink:1,textAlign:"center"}});export{SegmentedControl};export default SegmentedControl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{renderSlotIcon,slotIconView}from"../AppIcon/slotIcon.js";import{Chevron}from"../FieldBase/Chevron.js";import{FieldBase,FieldLabel,FieldMessage,fieldTextAsString,hasFieldText,RequiredMark,resolveFieldTextStyle,resolveVariantColors}from"../FieldBase/FieldBase.js";import{DEFAULT_OPTION_SHEET_LABELS,OptionSheet}from"../OptionSheet/OptionSheet.js";import{Text}from"../Text/index.js";import{TextInkContext}from"../Text/textInk.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SELECT_LABELS={placeholder:"Select…",noSelection:"No selection",selected:e=>`Selected: ${e}`,fallbackName:"Select",sheetName:"Options",searchPlaceholder:DEFAULT_OPTION_SHEET_LABELS.searchPlaceholder,empty:DEFAULT_OPTION_SHEET_LABELS.empty};const sameSelectValue=(e,t)=>String(e)===String(t),containsValue=(e,t)=>e.some(e=>sameSelectValue(e,t)),Select=forwardRef((e,t)=>{assertValidValue("Select","size",e.size,["sm","md","lg"]),assertValidValue("Select","variant",e.variant,["outline","filled","underline"]);const{options:l,getOptionLabel:i,getOptionValue:o,isOptionDisabled:s,getOptionDescription:r,getOptionIcon:n,placeholder:a,onOpenChange:c,searchable:d=!1,haptic:p,labels:u,label:h,help:x,title:S,required:m=!1,error:f,helperText:g,prefix:b,numberOfLines:y=1,disabled:v=!1,size:T="md",variant:C,leftIcon:L,rightIcon:j,chevronColor:_,chevronSize:O,radius:F,accessibilityLabel:V,labelStyle:E,style:I,triggerStyle:k,textStyle:z,optionStyle:A,selectedOptionStyle:H,optionTextStyle:P,selectedOptionTextStyle:D,testID:w}=e,B=!0===e.multi,N=u?{...DEFAULT_SELECT_LABELS,...u}:DEFAULT_SELECT_LABELS,M=useCallback(e=>i?i(e):e.label??"",[i]),R=useCallback(e=>o?o(e):e.value,[o]),U=useCallback(e=>s?s(e):!0===e.disabled,[s]),q=useCallback(e=>r?r(e):e.description,[r]),$=useCallback(e=>n?n(e):e.icon,[n]),G=useTheme(),J=useMemo(()=>buildStyles(G),[G]),K=resolveFieldSize(G,T),Q=resolveFieldTextStyle(G,{disabled:v}),W=C??G.settings.components.select?.defaultVariant??G.settings.components.field?.defaultVariant??"outline",[X,Y]=useState(!1),Z=useMemo(()=>{if(B){const t=e.value??[];return l.filter(e=>containsValue(t,R(e)))}const t=e.value;if(null==t)return[];const i=l.find(e=>sameSelectValue(R(e),t));return i?[i]:[]},[B,l,e.value,R]),ee=useCallback(()=>{if(v)return;const e=resolveHaptic(p,"selection");e&&triggerHaptic(e),Y(!0)},[v,p]),te=useCallback(()=>{Y(!1)},[]),le=useCallback(t=>{if(U(t))return;const l=R(t),i=resolveHaptic(p,"selection");if(i&&triggerHaptic(i),B){const t=e.value??[],i=containsValue(t,l)?t.filter(e=>!sameSelectValue(e,l)):[...t,l];return void e.onChange(i)}e.onChange(l),te()},[B,e,te,U,R,p]),ie=0===Z.length?a??N.placeholder:Z.map(e=>M(e)).join(", "),oe=0===Z.length,se=!0===f||hasFieldText(f),re=hasFieldText(h),ne=fieldTextAsString(h),ae=Math.round(1.4*K.text),ce=useMemo(()=>({fontSize:K.text,color:Q.placeholderColor}),[K.text,Q.placeholderColor]),de={color:v?G.colors["field-icon-disabled"]:X?G.colors["field-icon-focus"]:G.colors["field-icon"],size:K.icon,disabled:v,focused:X,error:se},pe=0===Z.length?a??N.noSelection:N.selected(Z.map(e=>M(e)).join(", ")),ue=V??`${ne??N.fallbackName}. ${pe}`;return _jsxs(View,{style:[J.container,I],testID:w,children:[re?_jsx(FieldLabel,{size:T,required:m,help:x,style:E,children:h}):null,_jsx(View,{ref:t,collapsable:!1,children:_jsxs(FieldBase,{size:T,variant:W,disabled:v,error:se,filled:Z.length>0,onPress:ee,radius:F,paddingHorizontal:"underline"===W?G.space.none:void 0,accessibilityRole:"button",accessibilityLabel:ue,accessibilityState:{disabled:v,expanded:X},"aria-disabled":v,"aria-expanded":X,style:k,slotAlign:1===y?"center":"top",slotLineHeight:1===y?void 0:ae,leading:L?slotIconView(L,renderSlotIcon(L,de)):null,trailing:j?slotIconView(j,renderSlotIcon(j,de)):_jsx(Chevron,{color:_??(v?G.colors["text-disabled"]:G.colors["text-subtle"]),size:O??K.icon,open:X,style:J.chevron}),children:[hasFieldText(b)?"string"==typeof b||"number"==typeof b?_jsx(Text,{variant:"body",style:[J.prefix,{color:Q.placeholderColor,fontSize:K.text,lineHeight:1===y?void 0:ae,marginRight:G.space.xs}],children:b}):_jsx(View,{style:[J.prefixNode,{minHeight:1===y?void 0:ae,justifyContent:"center",marginRight:G.space.xs}],children:_jsx(Text,{variant:"body",style:[J.prefix,{color:Q.placeholderColor,fontSize:K.text,lineHeight:1===y?void 0:ae}],children:_jsx(TextInkContext.Provider,{value:ce,children:b})})}):null,_jsxs(Text,{variant:"body",style:[J.triggerText,{color:oe?Q.placeholderColor:Q.color,fontSize:K.text,lineHeight:1===y?void 0:ae,...Q.weightStyle},z],numberOfLines:y,children:[ie,oe&&m&&!re?_jsx(RequiredMark,{}):null]})]})}),_jsx(FieldMessage,{size:T,error:se,text:se?f:g}),_jsx(OptionSheet,{open:X,onClose:te,onOpenChange:c,haptic:p,title:S??ne,accessibilityLabel:ne??(re?S:void 0)??a??N.sheetName,options:l,getOptionLabel:M,getOptionValue:R,isOptionDisabled:U,getOptionDescription:q,getOptionIcon:$,value:e.value,onChange:(e,t)=>le(t),multi:B,searchable:d,labels:{searchPlaceholder:N.searchPlaceholder,empty:N.empty},optionStyle:A,selectedOptionStyle:H,optionTextStyle:P,selectedOptionTextStyle:D,searchSelectionColor:resolveVariantColors(G,W).borderFocusedRepresentative})]})});Select.displayName="Select";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},label:{includeFontPadding:!1},triggerText:{flex:1,includeFontPadding:!1},errorText:{includeFontPadding:!1},prefix:{flexShrink:0,includeFontPadding:!1},prefixNode:{flexShrink:0},chevron:{marginLeft:e.space.sm}});export{Select};export default Select;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatDateTime}from"@webority/mobile-core";import{forwardRef,memo,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Modal,PixelRatio,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import Svg,{Path,Rect,Text as SvgText}from"react-native-svg";import{lightTheme,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Button}from"../Button/index.js";import{Input}from"../Input/index.js";import{Text}from"../Text/index.js";import{BASELINE_RATIO,buildSignatureSvg,distanceBetween,FALLBACK_WIDTH,pointOf,strokePath,typedFontSize}from"./signatureGeometry.js";import{writePng}from"./writePng";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SIGNATURE_PAD_LABELS=Object.freeze({pad:"Signature pad",padHint:"Draw with one finger. To sign without drawing, use the type your name action.",caption:"Sign above the line. To start with an up or down stroke, rest your finger a moment first.",typedCaption:"Your typed name is used as your signature.",undo:"Undo",clear:"Clear",typeInstead:"Type your name instead",drawInstead:"Draw instead",typedLabel:"Type your name",typedPlaceholder:"Your full name",empty:"Not signed",signed:"Signed",typingAnnouncement:"Signing by typing your name. Your typed name is used as your signature. Choose Draw instead to sign with your finger.",drawingAnnouncement:"Signing by drawing. Use one finger on the pad.",clearedAnnouncement:"Signature cleared",undoneAnnouncement:"Last stroke removed",emptyError:"Add a signature first.",expand:"Expand",done:"Done",close:"Close"});const STROKE_WIDTH=2.5,SIDEWAYS_TO_DRAW=6,UPRIGHT_TO_SCROLL=8,REST_TO_DRAW_MS=200,MIN_POINT_GAP=.8,DEFAULT_HEIGHT=180,EXPANDED_CHROME=200,DEFAULT_NAME_LENGTH=100,MAX_EXPORT_SCALE=3,MIN_TARGET=44,BASELINE_OPACITY=.3,DISABLED_OPACITY=.5,TARGET_STYLE={minHeight:44},defaultScriptFont=()=>Platform.select({ios:"Snell Roundhand",default:"cursive"}),cssFontStack=e=>"cursive"===e?"cursive":`'${e}', cursive`,useScreenReader=()=>{const[e,t]=useState(!1);return useEffect(()=>{let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(n=>{e&&t(n)});const n=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,n.remove()}},[]),e},StrokePath=memo(({points:e,color:t})=>_jsx(Path,{d:strokePath(e),stroke:t,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}));StrokePath.displayName="SignaturePadStroke";const Marks=({mode:e,strokes:t,name:n,color:a,fontFamily:r,width:o,height:i})=>"draw"===e?_jsx(_Fragment,{children:t.map(e=>_jsx(StrokePath,{points:e.points,color:a},e.id))}):n?_jsx(SvgText,{x:o/2,y:i*BASELINE_RATIO,fontSize:typedFontSize(o,n),fontFamily:r,textAnchor:"middle",fill:a,children:n}):null,SignaturePadSurface=forwardRef((e,t)=>{const{expandable:n,initialStrokes:a,onChange:r,initialTypedName:o="",onTypedNameChange:i,defaultMode:s="draw",onModeChange:l,onEmptyChange:d,allowTyped:c=!0,signedBy:u,signedAt:p,height:m=DEFAULT_HEIGHT,maxNameLength:h=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x="selection",disabled:T=!1,style:w,testID:b}=e;warnInvalidValue("SignaturePad","defaultMode",e.defaultMode,["draw","type"]);const _=useTheme(),E=void 0===g&&void 0===y,A=E?_.colors["text-body"]:g??lightTheme.colors["text-body"],C=E?_.colors.surface:y??lightTheme.colors.surface,v=E?lightTheme.colors["text-body"]:A,I=E?lightTheme.colors.surface:C,R=v!==A||I!==C,j=f??defaultScriptFont(),P=useMemo(()=>({...DEFAULT_SIGNATURE_PAD_LABELS,...S}),[S]),D=useScreenReader(),L=useRef(null),k=useRef(null),[F,M]=useState(0),[G,N]=useState(()=>(a??[]).map((e,t)=>({id:t+1,points:[...e]}))),B=useRef(G),O=useRef(G.length),H=useRef(null),V=useRef(null),[Y,$]=useState(c?s:"draw"),[z,U]=useState(o),[W,K]=useState(null),X=useRef(!1),{height:q}=useWindowDimensions(),[J,Q]=useState(!1),[Z,ee]=useState([]),te=useRef({onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d});useEffect(()=>{te.current={onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d}});const ne="draw"===Y&&!T,ae="draw"===Y?0===G.length:0===z.trim().length,re=useRef(null);useEffect(()=>{re.current!==ae&&(re.current=ae,te.current.onEmptyChange?.(ae))},[ae]);const oe=useCallback(e=>{B.current=e,N(e)},[]),ie=useCallback(()=>{K(Date.now()),te.current.onChange?.(B.current.map(e=>e.points))},[]),se=useMemo(()=>{const pan=e=>Gesture.Pan().enabled(ne).runOnJS(!0).onBegin(e=>{H.current=pointOf(e.x,e.y)}).onStart(t=>{V.current=e,O.current+=1;const n=pointOf(t.x,t.y);oe([...B.current,{id:O.current,points:[H.current??n,n]}])}).onUpdate(t=>{if(V.current!==e)return;const n=B.current[B.current.length-1],a=pointOf(t.x,t.y);distanceBetween(n.points[n.points.length-1],a)<.8||oe([...B.current.slice(0,-1),{...n,points:[...n.points,a]}])}).onFinalize(()=>{V.current===e&&(V.current=null,ie())}),e=pan("sideways").activeOffsetX([-6,6]).failOffsetY([-8,8]),t=pan("rested").activateAfterLongPress(200);return Gesture.Race(e,t)},[ne,oe,ie]),le=useCallback(e=>{$(e),te.current.onModeChange?.(e),announce("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);useEffect(()=>{D&&c&&!X.current&&"draw"===Y&&0===B.current.length&&le("type")},[D,c,Y,le]);const de=useCallback(()=>{X.current=!0,le("draw"===Y?"type":"draw")},[Y,le]),ce=useCallback(e=>{U(e),K(Date.now()),te.current.onTypedNameChange?.(e)},[]),ue=useCallback(()=>{"type"===Y?ce(""):(oe([]),ie()),announce(P.clearedAnnouncement)},[Y,ce,oe,ie,P.clearedAnnouncement]),pe=useCallback(()=>{"draw"===Y&&0!==B.current.length&&(oe(B.current.slice(0,-1)),ie(),announce(P.undoneAnnouncement))},[Y,oe,ie,P.undoneAnnouncement]),me=useCallback(()=>{ee(B.current.map(e=>e.points)),Q(!0)},[]),he=useCallback(()=>{Q(!1)},[]),ge=useCallback(()=>{oe(Z.map(e=>(O.current+=1,{id:O.current,points:[...e]}))),ie(),Q(!1)},[Z,oe,ie]),ye=F||FALLBACK_WIDTH;useImperativeHandle(t,()=>({toFile:()=>new Promise((e,t)=>{if(ae)return void t(new Error(P.emptyError));const n=R?k.current:L.current;if(!n)return void t(new Error("The signature pad is not on screen."));const a=Math.min(3,Math.max(1,PixelRatio.get()));n.toDataURL(n=>{try{e(writePng(n))}catch(e){t(e)}},{width:ye*a,height:m*a})}),toSvg:()=>buildSignatureSvg({width:ye,height:m,mode:Y,strokes:G.map(e=>e.points),typedName:z,ink:v,paper:I,strokeWidth:2.5,fontFamily:cssFontStack(j)}),clear:ue,undo:pe,isEmpty:()=>ae}),[ae,P.emptyError,ye,m,Y,G,z,R,v,I,j,ue,pe]);const fe=useMemo(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...c?[{name:"toggleMode",label:"draw"===Y?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,c,Y]),Se=useCallback(e=>{if(T)return;const{actionName:t}=e.nativeEvent;"undo"===t?pe():"clear"===t?ue():"toggleMode"===t&&c&&de()},[T,pe,ue,de,c]),xe=useCallback(e=>{M(e.nativeEvent.layout.width)},[]),Te=useMemo(()=>StyleSheet.create({root:{gap:_.space.sm},pad:{height:m,borderWidth:_.size.border,borderColor:_.colors.border,borderRadius:_.radius.md,...smoothCorners,overflow:"hidden",backgroundColor:C,opacity:T?.5:1},baseline:{position:"absolute",left:_.space.md,right:_.space.md,top:m*BASELINE_RATIO,height:StyleSheet.hairlineWidth,backgroundColor:A,opacity:.3},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:_.space.xs},trailing:{flexDirection:"row",alignItems:"center",gap:_.space.xs},expandedRoot:{flex:1,padding:_.space.md,gap:_.space.sm,backgroundColor:_.colors.bg},expandedBar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}),[_,m,C,A,T]),we=z.trim(),be=p??W,Ee=u&&!ae?`Signed by ${u}${be?`, ${formatDateTime(be)}`:""}`:null,Ae="type"===Y&&we?`${P.pad}. ${we}`:P.pad;return _jsxs(View,{style:[Te.root,w],testID:b,children:[_jsx(GestureDetector,{gesture:se,children:_jsxs(View,{style:Te.pad,onLayout:xe,accessible:!0,accessibilityRole:"image",accessibilityLabel:Ae,accessibilityHint:"draw"===Y?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:T},"aria-disabled":T,accessibilityActions:fe,onAccessibilityAction:Se,children:[R?_jsxs(Svg,{ref:k,style:StyleSheet.absoluteFill,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:I}),_jsx(Marks,{mode:Y,strokes:G,name:we,color:v,fontFamily:j,width:ye,height:m})]}):null,_jsxs(Svg,{ref:L,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:C}),_jsx(Marks,{mode:Y,strokes:G,name:we,color:A,fontFamily:j,width:ye,height:m})]}),_jsx(View,{pointerEvents:"none",style:Te.baseline})]})}),"type"===Y?_jsx(Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:z,onChangeText:ce,maxLength:h,disabled:T,autoComplete:"name",textContentType:"name",autoCapitalize:"words",autoCorrect:!1,returnKeyType:"done",testID:b?`${b}-name`:void 0}):null,_jsx(Text,{variant:"caption",color:"tertiary",children:"draw"===Y?P.caption:P.typedCaption}),_jsxs(View,{style:Te.actions,children:[c?_jsx(Button,{label:"draw"===Y?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:de,testID:b?`${b}-mode`:void 0}):_jsx(View,{}),"draw"===Y?_jsxs(View,{style:Te.trailing,children:[G.length>0?_jsxs(_Fragment,{children:[_jsx(Button,{label:P.undo,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:pe,testID:b?`${b}-undo`:void 0}),_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:b?`${b}-clear`:void 0})]}):null,n?_jsx(Button,{label:P.expand,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:me,testID:b?`${b}-expand`:void 0}):null]}):null,"type"===Y&&we?_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:b?`${b}-clear`:void 0}):null]}),Ee?_jsx(Text,{variant:"caption",color:"secondary",children:Ee}):null,n?_jsx(Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:he,children:_jsxs(ExpandedRoot,{style:Te.expandedRoot,children:[_jsxs(View,{style:Te.expandedBar,children:[_jsx(Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:he,testID:b?`${b}-close`:void 0}),_jsx(Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:ge,testID:b?`${b}-done`:void 0})]}),J?_jsx(SignaturePadSurface,{expandable:!1,defaultMode:"draw",allowTyped:!1,initialStrokes:Z,onChange:ee,height:Math.max(DEFAULT_HEIGHT,q-200),inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x,testID:b?`${b}-expanded`:void 0}):null]})}):null]})});SignaturePadSurface.displayName="SignaturePadSurface";const ExpandedRoot="android"===Platform.OS?GestureHandlerRootView:View,SignaturePad=forwardRef((e,t)=>_jsx(SignaturePadSurface,{...e,expandable:!0,ref:t}));SignaturePad.displayName="SignaturePad";export{SignaturePad};export default SignaturePad;
|
|
1
|
+
"use strict";import{formatDateTime}from"@webority/mobile-core";import{forwardRef,memo,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import{AccessibilityInfo,Modal,PixelRatio,Platform,StyleSheet,useWindowDimensions,View}from"react-native";import{Gesture,GestureDetector,GestureHandlerRootView}from"react-native-gesture-handler";import Svg,{Path,Rect,Text as SvgText}from"react-native-svg";import{lightTheme,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Button}from"../Button/index.js";import{Input}from"../Input/index.js";import{Text}from"../Text/index.js";import{BASELINE_RATIO,buildSignatureSvg,distanceBetween,FALLBACK_WIDTH,pointOf,strokePath,typedFontSize}from"./signatureGeometry.js";import{writePng}from"./writePng";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SIGNATURE_PAD_LABELS=Object.freeze({pad:"Signature pad",padHint:"Draw with one finger. To sign without drawing, use the type your name action.",caption:"Sign above the line. To start with an up or down stroke, rest your finger a moment first.",typedCaption:"Your typed name is used as your signature.",undo:"Undo",clear:"Clear",typeInstead:"Type your name instead",drawInstead:"Draw instead",typedLabel:"Type your name",typedPlaceholder:"Your full name",empty:"Not signed",signed:"Signed",typingAnnouncement:"Signing by typing your name. Your typed name is used as your signature. Choose Draw instead to sign with your finger.",drawingAnnouncement:"Signing by drawing. Use one finger on the pad.",clearedAnnouncement:"Signature cleared",undoneAnnouncement:"Last stroke removed",emptyError:"Add a signature first.",expand:"Expand",done:"Done",close:"Close"});const STROKE_WIDTH=2.5,SIDEWAYS_TO_DRAW=6,UPRIGHT_TO_SCROLL=8,REST_TO_DRAW_MS=200,MIN_POINT_GAP=.8,DEFAULT_HEIGHT=180,EXPANDED_CHROME=200,DEFAULT_NAME_LENGTH=100,MAX_EXPORT_SCALE=3,MIN_TARGET=44,BASELINE_OPACITY=.3,DISABLED_OPACITY=.5,TARGET_STYLE={minHeight:44},defaultScriptFont=()=>Platform.select({ios:"Snell Roundhand",default:"cursive"}),cssFontStack=e=>"cursive"===e?"cursive":`'${e}', cursive`,useScreenReader=()=>{const[e,t]=useState(!1);return useEffect(()=>{let e=!0;AccessibilityInfo.isScreenReaderEnabled().then(n=>{e&&t(n)});const n=AccessibilityInfo.addEventListener("screenReaderChanged",t);return()=>{e=!1,n.remove()}},[]),e},StrokePath=memo(({points:e,color:t})=>_jsx(Path,{d:strokePath(e),stroke:t,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}));StrokePath.displayName="SignaturePadStroke";const Marks=({mode:e,strokes:t,name:n,color:a,fontFamily:r,width:o,height:i})=>"draw"===e?_jsx(_Fragment,{children:t.map(e=>_jsx(StrokePath,{points:e.points,color:a},e.id))}):n?_jsx(SvgText,{x:o/2,y:i*BASELINE_RATIO,fontSize:typedFontSize(o,n),fontFamily:r,textAnchor:"middle",fill:a,children:n}):null,SignaturePadSurface=forwardRef((e,t)=>{const{expandable:n,initialStrokes:a,onChange:r,initialTypedName:o="",onTypedNameChange:i,defaultMode:s="draw",onModeChange:l,onEmptyChange:d,allowTyped:c=!0,signedBy:u,signedAt:p,height:m=DEFAULT_HEIGHT,maxNameLength:h=DEFAULT_NAME_LENGTH,inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x="selection",disabled:T=!1,style:b,testID:w}=e;assertValidValue("SignaturePad","defaultMode",e.defaultMode,["draw","type"]);const _=useTheme(),E=void 0===g&&void 0===y,A=E?_.colors["text-body"]:g??lightTheme.colors["text-body"],C=E?_.colors.surface:y??lightTheme.colors.surface,R=E?lightTheme.colors["text-body"]:A,v=E?lightTheme.colors.surface:C,I=R!==A||v!==C,j=f??defaultScriptFont(),P=useMemo(()=>({...DEFAULT_SIGNATURE_PAD_LABELS,...S}),[S]),D=useScreenReader(),L=useRef(null),k=useRef(null),[F,M]=useState(0),[G,N]=useState(()=>(a??[]).map((e,t)=>({id:t+1,points:[...e]}))),B=useRef(G),O=useRef(G.length),H=useRef(null),V=useRef(null),[Y,$]=useState(c?s:"draw"),[z,U]=useState(o),[W,K]=useState(null),X=useRef(!1),{height:q}=useWindowDimensions(),[J,Q]=useState(!1),[Z,ee]=useState([]),te=useRef({onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d});useEffect(()=>{te.current={onChange:r,onTypedNameChange:i,onModeChange:l,onEmptyChange:d}});const ne="draw"===Y&&!T,ae="draw"===Y?0===G.length:0===z.trim().length,re=useRef(null);useEffect(()=>{re.current!==ae&&(re.current=ae,te.current.onEmptyChange?.(ae))},[ae]);const oe=useCallback(e=>{B.current=e,N(e)},[]),ie=useCallback(()=>{K(Date.now()),te.current.onChange?.(B.current.map(e=>e.points))},[]),se=useMemo(()=>{const pan=e=>Gesture.Pan().enabled(ne).runOnJS(!0).onBegin(e=>{H.current=pointOf(e.x,e.y)}).onStart(t=>{V.current=e,O.current+=1;const n=pointOf(t.x,t.y);oe([...B.current,{id:O.current,points:[H.current??n,n]}])}).onUpdate(t=>{if(V.current!==e)return;const n=B.current[B.current.length-1],a=pointOf(t.x,t.y);distanceBetween(n.points[n.points.length-1],a)<.8||oe([...B.current.slice(0,-1),{...n,points:[...n.points,a]}])}).onFinalize(()=>{V.current===e&&(V.current=null,ie())}),e=pan("sideways").activeOffsetX([-6,6]).failOffsetY([-8,8]),t=pan("rested").activateAfterLongPress(200);return Gesture.Race(e,t)},[ne,oe,ie]),le=useCallback(e=>{$(e),te.current.onModeChange?.(e),announce("type"===e?P.typingAnnouncement:P.drawingAnnouncement)},[P.typingAnnouncement,P.drawingAnnouncement]);useEffect(()=>{D&&c&&!X.current&&"draw"===Y&&0===B.current.length&&le("type")},[D,c,Y,le]);const de=useCallback(()=>{X.current=!0,le("draw"===Y?"type":"draw")},[Y,le]),ce=useCallback(e=>{U(e),K(Date.now()),te.current.onTypedNameChange?.(e)},[]),ue=useCallback(()=>{"type"===Y?ce(""):(oe([]),ie()),announce(P.clearedAnnouncement)},[Y,ce,oe,ie,P.clearedAnnouncement]),pe=useCallback(()=>{"draw"===Y&&0!==B.current.length&&(oe(B.current.slice(0,-1)),ie(),announce(P.undoneAnnouncement))},[Y,oe,ie,P.undoneAnnouncement]),me=useCallback(()=>{ee(B.current.map(e=>e.points)),Q(!0)},[]),he=useCallback(()=>{Q(!1)},[]),ge=useCallback(()=>{oe(Z.map(e=>(O.current+=1,{id:O.current,points:[...e]}))),ie(),Q(!1)},[Z,oe,ie]),ye=F||FALLBACK_WIDTH;useImperativeHandle(t,()=>({toFile:()=>new Promise((e,t)=>{if(ae)return void t(new Error(P.emptyError));const n=I?k.current:L.current;if(!n)return void t(new Error("The signature pad is not on screen."));const a=Math.min(3,Math.max(1,PixelRatio.get()));n.toDataURL(n=>{try{e(writePng(n))}catch(e){t(e)}},{width:ye*a,height:m*a})}),toSvg:()=>buildSignatureSvg({width:ye,height:m,mode:Y,strokes:G.map(e=>e.points),typedName:z,ink:R,paper:v,strokeWidth:2.5,fontFamily:cssFontStack(j)}),clear:ue,undo:pe,isEmpty:()=>ae}),[ae,P.emptyError,ye,m,Y,G,z,I,R,v,j,ue,pe]);const fe=useMemo(()=>[{name:"undo",label:P.undo},{name:"clear",label:P.clear},...c?[{name:"toggleMode",label:"draw"===Y?P.typeInstead:P.drawInstead}]:[]],[P.undo,P.clear,P.typeInstead,P.drawInstead,c,Y]),Se=useCallback(e=>{if(T)return;const{actionName:t}=e.nativeEvent;"undo"===t?pe():"clear"===t?ue():"toggleMode"===t&&c&&de()},[T,pe,ue,de,c]),xe=useCallback(e=>{M(e.nativeEvent.layout.width)},[]),Te=useMemo(()=>StyleSheet.create({root:{gap:_.space.sm},pad:{height:m,borderWidth:_.size.border,borderColor:_.colors.border,borderRadius:_.radius.md,...smoothCorners,overflow:"hidden",backgroundColor:C,opacity:T?.5:1},baseline:{position:"absolute",left:_.space.md,right:_.space.md,top:m*BASELINE_RATIO,height:StyleSheet.hairlineWidth,backgroundColor:A,opacity:.3},actions:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:_.space.xs},trailing:{flexDirection:"row",alignItems:"center",gap:_.space.xs},expandedRoot:{flex:1,padding:_.space.md,gap:_.space.sm,backgroundColor:_.colors.bg},expandedBar:{flexDirection:"row",alignItems:"center",justifyContent:"space-between"}}),[_,m,C,A,T]),be=z.trim(),we=p??W,Ee=u&&!ae?`Signed by ${u}${we?`, ${formatDateTime(we)}`:""}`:null,Ae="type"===Y&&be?`${P.pad}. ${be}`:P.pad;return _jsxs(View,{style:[Te.root,b],testID:w,children:[_jsx(GestureDetector,{gesture:se,children:_jsxs(View,{style:Te.pad,onLayout:xe,accessible:!0,accessibilityRole:"image",accessibilityLabel:Ae,accessibilityHint:"draw"===Y?P.padHint:void 0,accessibilityValue:{text:ae?P.empty:P.signed},accessibilityState:{disabled:T},"aria-disabled":T,accessibilityActions:fe,onAccessibilityAction:Se,children:[I?_jsxs(Svg,{ref:k,style:StyleSheet.absoluteFill,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:v}),_jsx(Marks,{mode:Y,strokes:G,name:be,color:R,fontFamily:j,width:ye,height:m})]}):null,_jsxs(Svg,{ref:L,width:"100%",height:m,children:[_jsx(Rect,{x:"0",y:"0",width:"100%",height:"100%",fill:C}),_jsx(Marks,{mode:Y,strokes:G,name:be,color:A,fontFamily:j,width:ye,height:m})]}),_jsx(View,{pointerEvents:"none",style:Te.baseline})]})}),"type"===Y?_jsx(Input,{label:P.typedLabel,placeholder:P.typedPlaceholder,value:z,onChangeText:ce,maxLength:h,disabled:T,autoComplete:"name",textContentType:"name",autoCapitalize:"words",autoCorrect:!1,returnKeyType:"done",testID:w?`${w}-name`:void 0}):null,_jsx(Text,{variant:"caption",color:"tertiary",children:"draw"===Y?P.caption:P.typedCaption}),_jsxs(View,{style:Te.actions,children:[c?_jsx(Button,{label:"draw"===Y?P.typeInstead:P.drawInstead,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:de,testID:w?`${w}-mode`:void 0}):_jsx(View,{}),"draw"===Y?_jsxs(View,{style:Te.trailing,children:[G.length>0?_jsxs(_Fragment,{children:[_jsx(Button,{label:P.undo,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:pe,testID:w?`${w}-undo`:void 0}),_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:w?`${w}-clear`:void 0})]}):null,n?_jsx(Button,{label:P.expand,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:me,testID:w?`${w}-expand`:void 0}):null]}):null,"type"===Y&&be?_jsx(Button,{label:P.clear,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,disabled:T,onPress:ue,testID:w?`${w}-clear`:void 0}):null]}),Ee?_jsx(Text,{variant:"caption",color:"secondary",children:Ee}):null,n?_jsx(Modal,{visible:J,animationType:"slide",presentationStyle:"fullScreen",onRequestClose:he,children:_jsxs(ExpandedRoot,{style:Te.expandedRoot,children:[_jsxs(View,{style:Te.expandedBar,children:[_jsx(Button,{label:P.close,variant:"ghost",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:he,testID:w?`${w}-close`:void 0}),_jsx(Button,{label:P.done,variant:"solid",tone:"primary",size:"md",style:TARGET_STYLE,haptic:x,onPress:ge,testID:w?`${w}-done`:void 0})]}),J?_jsx(SignaturePadSurface,{expandable:!1,defaultMode:"draw",allowTyped:!1,initialStrokes:Z,onChange:ee,height:Math.max(DEFAULT_HEIGHT,q-200),inkColor:g,paperColor:y,scriptFontFamily:f,labels:S,haptic:x,testID:w?`${w}-expanded`:void 0}):null]})}):null]})});SignaturePadSurface.displayName="SignaturePadSurface";const ExpandedRoot="android"===Platform.OS?GestureHandlerRootView:View,SignaturePad=forwardRef((e,t)=>_jsx(SignaturePadSurface,{...e,expandable:!0,ref:t}));SignaturePad.displayName="SignaturePad";export{SignaturePad};export default SignaturePad;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useMemo,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{toBackgroundImage}from"../../theme/Gradient.js";import{useScreenDimensions}from"../../utils/index.js";import{
|
|
1
|
+
"use strict";import{useMemo,useState}from"react";import{Animated,StyleSheet,View}from"react-native";import{useReducedMotion}from"../../hooks/useReducedMotion.js";import{useTheme}from"../../theme/index.js";import{toBackgroundImage}from"../../theme/Gradient.js";import{useScreenDimensions}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{useSkeletonClock}from"./SkeletonClock.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{jsx as _jsx}from"react/jsx-runtime";export const DEFAULT_SKELETON_LABELS=Object.freeze({loading:"Loading"});const resolveRadius=(e,t)=>"number"==typeof t?t:e.radius[t],resolveWidth=e=>void 0===e?"100%":e,radiusForShape=(e,t,s,o,i)=>{if(void 0!==i)return resolveRadius(e,i);switch(t){case"circle":return"number"==typeof s?Math.min(s,o)/2:o/2;case"rounded":return e.radius.md;default:return e.radius.sm}},Skeleton=e=>{const{shape:t="rect",width:s="100%",height:o=16,radius:i,variant:r,colors:n,labels:a,style:l,testID:u}=e;assertValidValue("Skeleton","shape",e.shape,["rect","rounded","circle","text"]),assertValidValue("Skeleton","variant",e.variant,["shimmer","pulse","none"]);const m=useTheme(),d=useSkeletonDefaults(),c=useSkeletonClock(),h=useReducedMotion(),p=r??d.variant??"shimmer",S=h&&"auto"===(d.animation??"auto");let k=p;c.enabled?S&&"shimmer"===p&&(k="pulse"):k="none";const g=n?.background??d.colors?.background??m.colors.skeleton,y=n?.highlight??d.colors?.highlight??m.colors["skeleton-highlight"],{responsive:b}=useScreenDimensions(),x=useMemo(()=>buildStyles(),[]),f=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...a}),[a]),v=resolveWidth(s),j=b.size(o),w=radiusForShape(m,t,v,j,i),[L,V]=useState(0),M=useMemo(()=>L<=0?0:Math.max(48,.7*L),[L]),R=useMemo(()=>L<=0?0:c.shimmer.interpolate({inputRange:[0,1],outputRange:[-M,L]}),[c.shimmer,M,L]),_=useMemo(()=>"none"===k?null:"pulse"===k?_jsx(Animated.View,{pointerEvents:"none",style:[StyleSheet.absoluteFill,{backgroundColor:y,opacity:c.pulse.interpolate({inputRange:[0,1],outputRange:[0,.55]})}]}):L<=0?null:_jsx(Animated.View,{pointerEvents:"none",style:[x.shimmerBand,{width:M,transform:[{translateX:R}],experimental_backgroundImage:[toBackgroundImage({colors:["transparent",y,"transparent"],locations:[0,.5,1],start:{x:0,y:.5},end:{x:1,y:.5}})]}]}),[k,y,c.pulse,L,x.shimmerBand,M,R]);return _jsx(View,{onLayout:e=>{const t=e.nativeEvent.layout.width;t!==L&&V(t)},accessible:!0,accessibilityLabel:f.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",testID:u,style:[x.base,{width:v,height:j,borderRadius:w,...smoothCorners,backgroundColor:g},l],children:_})};Skeleton.displayName="Skeleton";const SkeletonCircle=({size:e,style:t,...s})=>{const{responsive:o}=useScreenDimensions(),i=o.size(e);return _jsx(Skeleton,{...s,shape:"circle",width:i,height:e,style:t})};SkeletonCircle.displayName="SkeletonCircle";const SkeletonText=({lines:e=3,lastLineWidth:t="60%",spacing:s,fontSize:o,variant:i,radius:r="sm",width:n="100%",labels:a,style:l,testID:u})=>{const m=useTheme(),d=s??m.space.xs,c=Math.max(1,e);return _jsx(View,{style:l,testID:u,children:Array.from({length:c}).map((e,s)=>_jsx(Skeleton,{shape:"text",width:s===c-1&&c>1?t:n,height:o??m.text.base.size,radius:r,variant:i,labels:a,style:s<c-1?{marginBottom:d}:void 0},s))})};SkeletonText.displayName="SkeletonText";const buildStyles=()=>StyleSheet.create({base:{overflow:"hidden"},shimmerBand:{position:"absolute",top:0,bottom:0,left:0}});export{Skeleton,SkeletonCircle,SkeletonText};export default Skeleton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{Children,cloneElement,isValidElement,useEffect,useMemo,useRef}from"react";import{Animated,Image,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import React,{Children,cloneElement,isValidElement,useEffect,useMemo,useRef}from"react";import{Animated,Image,StyleSheet,Text,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{Text as LibraryText}from"../Text/index.js";import{DEFAULT_SKELETON_LABELS,Skeleton}from"./Skeleton.js";import{useSkeletonDefaults}from"./SkeletonProvider.js";import{SkeletonSkip}from"./SkeletonSkip.js";import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";const DEFAULT_REVEAL_FADE_MS=300,flattenStyle=e=>{if(!e)return{};return StyleSheet.flatten(e)??{}},resolveWidth=(e,t)=>"number"==typeof e?e:"string"!=typeof e||"auto"!==e&&"100%"!==e&&!/^\d+(\.\d+)?%$/.test(e)?t:e,resolveRadius=(e,t)=>"number"==typeof e?e:t,skeletonizeNode=(e,t,i,r,n="r")=>{if(null==t||"boolean"==typeof t)return null;if("string"==typeof t||"number"==typeof t)return _jsx(Skeleton,{shape:"text",width:"60%",height:14,variant:i,colors:r},`${n}-text`);if(Array.isArray(t))return Children.map(t,(t,s)=>skeletonizeNode(e,t,i,r,`${n}-${s}`));if(!isValidElement(t))return null;const s=t,o=s.props??{},l=s.type;if(l===SkeletonSkip)return cloneElement(s,{key:`${n}-skip`});if("function"==typeof l||"object"==typeof l){const e=l.Skeleton;if(e){return _jsx(e,{...o},`${n}-self`)}}if(l===Image){const e=flattenStyle(o.style),t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:120,l=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:l,variant:i,colors:r,style:{margin:"number"==typeof e.margin?e.margin:void 0}},`${n}-img`)}if(l===Text||l===LibraryText){const t=flattenStyle(o.style),s="number"==typeof t.fontSize?t.fontSize:e.text.base.size,l=resolveWidth(t.width,"85%");return _jsx(Skeleton,{shape:"text",width:l,height:Math.round(1.15*s),variant:i,colors:r,style:{marginVertical:e.space.xxs}},`${n}-txt`)}if(null!=o.children)return cloneElement(s,{key:`${n}-w`},skeletonizeNode(e,o.children,i,r,`${n}-c`));if(l===View){const e=flattenStyle(o.style);if(null!=e.width||null!=e.height){const t=resolveWidth(e.width,"100%"),s="number"==typeof e.height?e.height:20,o=resolveRadius(e.borderRadius,"sm");return _jsx(Skeleton,{width:t,height:s,radius:o,variant:i,colors:r},`${n}-vw`)}}return cloneElement(s,{key:`${n}-leaf`})},SkeletonContent=e=>{const{loading:t,children:i,placeholder:r,variant:n,count:s=1,colors:o,labels:l,fadeDuration:a,style:u,testID:c}=e;assertValidValue("SkeletonContent","variant",e.variant,["shimmer","pulse","none"]);const d=useTheme(),m=useMemo(()=>({...DEFAULT_SKELETON_LABELS,...l}),[l]),f=useSkeletonDefaults(),h=usePresenceMotion(),y=a??f.fadeDuration??(h.reduced?h.duration("default"):300),p=useRef(t),S=useRef(createAnimatedValue(t?0:1)).current;if(useEffect(()=>{let e;return p.current&&!t?(S.setValue(0),e=Animated.timing(S,{toValue:1,duration:y,useNativeDriver:!0}),e.start()):!p.current&&t&&S.setValue(1),p.current=t,()=>e?.stop()},[t,S,y]),!t)return y<=0?_jsx(_Fragment,{children:i}):_jsx(Animated.View,{style:[u,{opacity:S}],testID:c,children:i});if(void 0!==r){const e=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:r},`sk-ph-${t}`)):r;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:e})}const b=s>1?Array.from({length:s},(e,t)=>_jsx(React.Fragment,{children:i},`sk-rep-${t}`)):i;return _jsx(View,{style:u,testID:c,accessible:!0,accessibilityLabel:m.loading,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,accessibilityLiveRegion:"polite",children:skeletonizeNode(d,b,n,o)})};SkeletonContent.displayName="SkeletonContent";export{SkeletonContent};export default SkeletonContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import React,{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{
|
|
1
|
+
"use strict";import React,{forwardRef,useCallback,useMemo,useRef,useState}from"react";import{StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SLIDE_TO_CONFIRM_LABELS=Object.freeze({slide:"Slide to confirm",confirmed:"Confirmed",confirmAction:"Confirm"});const SIZE_MAP={sm:{height:44,pad:"xxs"},md:{height:56,pad:"xs"},lg:{height:64,pad:"sm"}},Chevron=({color:e,size:t})=>_jsx(View,{style:{width:0,height:0,borderTopWidth:.4*t,borderBottomWidth:.4*t,borderLeftWidth:.55*t,borderTopColor:"transparent",borderBottomColor:"transparent",borderLeftColor:e,marginLeft:.2*t}}),SlideToConfirm=forwardRef((e,t)=>{const{onConfirm:i,label:a,tone:r="primary",size:o="md",disabled:s=!1,threshold:n=.9,resetAfter:l=!1,haptic:c,icon:d,labels:u,style:m,trackStyle:h,handleStyle:f,labelStyle:p,testID:b}=e;assertValidValue("SlideToConfirm","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SlideToConfirm","size",e.size,["sm","md","lg"]);const g=useMemo(()=>({...DEFAULT_SLIDE_TO_CONFIRM_LABELS,...u}),[u]),S=useMemo(()=>[{name:"activate",label:g.confirmAction},{name:"increment",label:g.confirmAction}],[g.confirmAction]),v=useTheme(),y=SIZE_MAP[o],C=v.space[y.pad],x=y.height-2*C,A=useMemo(()=>buildStyles(v,y),[v,y]),w=v.colors[r],[T,j]=useState(!1),_=useSharedValue(0),V=useSharedValue(0),E=useSharedValue(0),k=useRef(null),L=useCallback(()=>{const e=resolveHaptic(c,"notificationSuccess");e&&triggerHaptic(e)},[c]),M=useCallback(()=>{j(!1),_.value=withSpring(0,{damping:18,stiffness:160,mass:1})},[_]),R=useCallback(()=>{j(!0),L(),i(),!1!==l&&(k.current&&clearTimeout(k.current),k.current=setTimeout(M,l))},[L,i,l,M]),D=useCallback(e=>{if(s||T)return;const{actionName:t}=e.nativeEvent;"activate"!==t&&"increment"!==t||R()},[s,T,R]);React.useEffect(()=>()=>{cancelAnimation(_),k.current&&clearTimeout(k.current)},[_]);const I=useCallback(e=>{V.value=Math.max(0,e.nativeEvent.layout.width-x-2*C)},[V,x,C]),O=useMemo(()=>{const e=n,t={damping:18,stiffness:160,mass:1},i={duration:v.motion.duration.fast,easing:Easing.out(Easing.cubic)};return Gesture.Pan().enabled(!s&&!T).minDistance(0).onStart(()=>{"worklet";E.value=_.value}).onUpdate(e=>{"worklet";_.value=Math.min(Math.max(E.value+e.translationX,0),V.value)}).onEnd(()=>{"worklet";V.value>0&&_.value>=V.value*e?(_.value=withTiming(V.value,i),runOnJS(R)()):_.value=withSpring(0,t)})},[s,T,n,_,V,E,R,v.motion.duration.fast]),z=useAnimatedStyle(()=>({transform:[{translateX:_.value}]}),[_]),F=useAnimatedStyle(()=>({width:_.value+x+C}),[_,x,C]),W=useAnimatedStyle(()=>{const e=V.value>0?V.value:1;return{opacity:Math.max(0,1-_.value/(.6*e))}},[V,_]);return _jsxs(View,{ref:t,style:[A.track,{backgroundColor:v.colors["bg-subtle"]},h,m],onLayout:I,testID:b,accessibilityRole:"adjustable",accessibilityLabel:T?g.confirmed:a??g.slide,accessibilityState:{disabled:s},"aria-disabled":s,accessibilityActions:S,onAccessibilityAction:D,children:[_jsx(Animated.View,{style:[A.fill,{backgroundColor:w,opacity:s?.5:1},F],pointerEvents:"none"}),_jsx(Animated.View,{style:[A.labelWrap,W],pointerEvents:"none",children:_jsx(Text,{variant:"body",style:[A.label,{color:v.colors["text-muted"]},p],numberOfLines:1,children:T?g.confirmed:a??g.slide})}),_jsx(GestureDetector,{gesture:O,children:_jsx(Animated.View,{style:[A.handle,{width:x,height:x,borderRadius:v.radius.pill,...smoothCorners,backgroundColor:v.colors.surface,opacity:s?.5:1,...v.shadow.card},f,z],children:d??_jsx(Chevron,{color:w,size:.5*x})})})]})});SlideToConfirm.displayName="SlideToConfirm";const buildStyles=(e,t)=>StyleSheet.create({track:{height:t.height,borderRadius:e.radius.pill,...smoothCorners,justifyContent:"center",overflow:"hidden",padding:e.space[t.pad]},fill:{position:"absolute",left:0,top:0,bottom:0,borderRadius:e.radius.pill,...smoothCorners},labelWrap:{position:"absolute",left:t.height,right:t.height},label:{textAlign:"center",includeFontPadding:!1},handle:{alignItems:"center",justifyContent:"center"}});export{SlideToConfirm};export default SlideToConfirm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useControllableState}from"../../hooks/index.js";import{resolveSliderSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{smoothCorners}from"../../utils/corners.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Text}from"../Text/index.js";import{sliderToneInk}from"./valueText.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,n=String(i).split(".")[1]?.length??0,s=n>0?Number(r.toFixed(n)):r;return clamp(s,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),Slider=forwardRef((e,t)=>{const{min:a=0,max:i=100,step:r=1,disabled:n=!1,tone:s="primary",size:o="md",variant:l="default",showLabel:u=!1,snapThumb:c=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:b,style:p,containerStyle:f,trackStyle:g,fillStyle:v,thumbStyle:w,labelStyle:y,thumbPressScale:S,labelShowDuration:k,labelOpacity:C,testID:x}=e;warnInvalidValue("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Slider","size",e.size,["sm","md","lg"]),warnInvalidValue("Slider","variant",e.variant,["default","inset","minimal","bar"]);const A=useTheme(),V=useMemo(()=>{const e=resolveSliderSize(A,o);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[A,o]),j=useMemo(()=>"default"===l?V:VARIANT_SIZE_MAP[l][o],[V,o,l]),M="inset"===l?j.trackHeight/2:0,_=A.settings.components.slider?.thumbPressAnimation??!1,D=S??1.1,H=k??A.motion.duration.fast,E=C??1,O=useMemo(()=>buildStyles(A,j),[A,j]),T=useMemo(()=>({damping:A.motion.spring.snappy.damping,stiffness:A.motion.spring.snappy.stiffness,mass:A.motion.spring.snappy.mass}),[A.motion.spring.snappy]),[R,I]=useState(0),W=A.colors[s],L=sliderToneInk(A,s),N=!0===e.range,[P,X]=useControllableState({value:e.value,defaultValue:e.defaultValue??(N?[a,i]:a),onChange:e.onChange}),B=useSharedValue(0),F=useSharedValue(0),z=useSharedValue(N?P[0]:P),G=useSharedValue(N?P[1]:P),J=useSharedValue(0),U=useSharedValue(0),Z=useSharedValue(1),$=useSharedValue(1),q="always"===u,K=useSharedValue(q?1:0),Q=useSharedValue(q?1:0),Y=useMemo(()=>10**(String(r).split(".")[1]?.length??0),[r]);useEffect(()=>()=>{cancelAnimation(B),cancelAnimation(F),cancelAnimation(Z),cancelAnimation($),cancelAnimation(K),cancelAnimation(Q)},[B,F,Z,$,K,Q]);const ee=useCallback((e,t)=>{const r=t-2*M;return i===a||r<=0?M:M+(e-a)/(i-a)*r},[a,i,M]),te=useCallback((e,t)=>{const n=t-2*M;if(n<=0)return a;const s=clamp((e-M)/n,0,1);return snapToStep(a+s*(i-a),a,i,r)},[a,i,r,M]),ae=useRef(!1),ie=A.motion.duration.fast,re=useRef(P);re.current=P;const ne=useRef(R);ne.current=R;const se=useCallback((e=!1)=>{const t=ne.current;if(t<=0)return;const place=t=>e?withTiming(t,{duration:ie,easing:Easing.out(Easing.cubic)}):t,a=re.current;if(N){const[e,i]=a,r=Math.min(e,i),n=Math.max(e,i);z.value=r,G.value=n,B.value=place(ee(r,t)),F.value=place(ee(n,t))}else{const e=a;z.value=e,G.value=e,B.value=place(ee(e,t))}},[N,ee,z,G,B,F,ie]),[oe,le]=useState(0),ue=useRef(!1),ce=useCallback(e=>{ae.current=e,e||(ue.current=!0,le(e=>e+1))},[]);useEffect(()=>{if(ae.current)return;const e=ue.current;ue.current=!1,se(e)},[JSON.stringify(P),R,oe,se]);const de=useCallback(e=>{const t=e.nativeEvent.layout.width;U.value=t,I(t)},[U]),me=useCallback((e,t)=>{X(N?[e,t]:e)},[N,X]),he=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e)},[b]),be=useRef(me);be.current=me;const pe=useRef(he);pe.current=he;const fe=useCallback((e,t)=>be.current(e,t),[]),ge=useCallback(()=>pe.current(),[]),ve=Math.max(0,(44-j.thumbDiameter)/2),we=ve>0?ve:void 0,ye=useCallback(e=>{const t="low"===e?B:F,s="low"===e?z:G,o="low"===e?G:z,l="low"===e?Z:$,d="low"===e?K:Q,m="low"===e,h=a,b=i,p=r,f=Y,g=N,v=D,w=_,y=!0===u,S=c,k=E,C=H,x=T,A=M,follow=e=>{"worklet";const a=U.value-2*A;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(J.value+e,A),U.value-A);let r=h+(i-A)/a*(b-h);p>0&&(r=Math.round((r-h)/p)*p+h,r=Math.round(r*f)/f),r=Math.min(Math.max(r,h),b),g&&(m&&r>o.value&&(r=o.value),!m&&r<o.value&&(r=o.value)),t.value=S||b===h?b===h?A:A+(r-h)/(b-h)*a:g?m?Math.min(i,F.value):Math.max(i,B.value):i,r!==s.value&&(s.value=r,r!==h&&r!==b||runOnJS(ge)(),runOnJS(fe)(z.value,G.value))},V=Gesture.Pan().enabled(!n).minDistance(0);return(void 0===we?V:V.hitSlop(we)).onStart(()=>{"worklet";runOnJS(ce)(!0),J.value=t.value,w&&(l.value=withSpring(v,x)),y&&(d.value=withTiming(k,{duration:C,easing:Easing.out(Easing.cubic)})),runOnJS(ge)()}).onUpdate(e=>{"worklet";follow(e.translationX)}).onEnd(e=>{"worklet";follow(e.translationX),w&&(l.value=withSpring(1,x)),y&&(d.value=withTiming(0,{duration:C,easing:Easing.out(Easing.cubic)}))}).onFinalize(()=>{"worklet";runOnJS(ce)(!1)})},[n,a,i,r,Y,N,D,_,u,c,E,H,T,M,we,fe,ge,ce,B,F,z,G,Z,$,K,Q,J,U]),Se=useMemo(()=>ye("low"),[ye]),ke=useMemo(()=>ye("high"),[ye]),Ce=useCallback(e=>{if(n||N||R<=0)return;const t=clamp(e.nativeEvent.locationX,0,R),a=te(t,R);a!==z.value&&(he(),z.value=a,B.value=withTiming(ee(a,R),{duration:A.motion.duration.fast,easing:Easing.out(Easing.cubic)}),me(a,a))},[n,N,R,te,ee,me,he,B,z,A.motion.duration.fast]),xe=useCallback(e=>{if(n)return;const t="increment"===e.nativeEvent.actionName?r:-r,s=r>0?Math.round(t*Y)/Y:t;if(N){const e=Math.round((z.value+s)*Y)/Y,t=clamp(e,a,G.value);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,G.value))}else{const e=Math.round((z.value+s)*Y)/Y,t=clamp(e,a,i);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,t))}},[n,r,Y,N,a,i,ee,R,B,z,G,me,he]),Ae=j.thumbDiameter/2,Ve=n?A.colors["surface-disabled"]:W,je="inset"===l?{backgroundColor:Ve,borderColor:A.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===l?{backgroundColor:Ve,borderWidth:0}:"bar"===l?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:A.colors.surface,borderColor:Ve},Me=useAnimatedStyle(()=>{const e=U.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=n?.55:1;if(N){const a=Math.max(0,F.value-B.value+2*M);return{opacity:t,transform:[{translateX:B.value-M},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:B.value+M-e},{scaleX:1}]}},[U,n,N,F,B,M]),De=useAnimatedStyle(()=>({transform:[{translateX:B.value-Ae},{scale:Z.value}]}),[B,Ae,Z]),He=useAnimatedStyle(()=>({transform:[{translateX:F.value-Ae},{scale:$.value}]}),[F,Ae,$]),Ee=useAnimatedStyle(()=>({opacity:K.value}),[K]),Oe=useAnimatedStyle(()=>({opacity:Q.value}),[Q]),clampDisplay=e=>clamp(e,a,i),Te=clampDisplay(N?Math.min(...P):P),Re=clampDisplay(N?Math.max(...P):P);return _jsx(View,{ref:t,style:[O.container,f,p],testID:x,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:n},"aria-disabled":n,accessibilityValue:N?{min:a,max:i,now:Te,text:`${Te} to ${Re}`}:{min:a,max:i,now:Te},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:xe,children:_jsx(Pressable,{onPress:Ce,disabled:n||N,style:O.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsxs(View,{style:O.trackWrap,onLayout:de,children:[_jsxs(View,{style:O.trackClip,pointerEvents:"none",children:[_jsx(View,{style:[O.track,{backgroundColor:n?A.colors["surface-disabled"]:A.colors.border},g]}),_jsx(Animated.View,{style:[O.fill,{backgroundColor:n?A.colors["surface-disabled"]:W},v,Me]})]}),_jsx(GestureDetector,{gesture:Se,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ae,...smoothCorners,opacity:n?.55:1},je,w,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Ee],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Te):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Te)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}),N?_jsx(GestureDetector,{gesture:ke,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ae,...smoothCorners,opacity:n?.55:1},je,w,He],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Oe],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Re):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Re)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-t.trackHeight)/2,borderRadius:t.trackHeight/2,...smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,...smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,...smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(i-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,...smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,...smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",...Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};export{Slider};export default Slider;
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Platform,Pressable,StyleSheet,View}from"react-native";import{Gesture,GestureDetector}from"react-native-gesture-handler";import Animated,{cancelAnimation,Easing,runOnJS,useAnimatedStyle,useSharedValue,withSpring,withTiming}from"react-native-reanimated";import{useControllableState}from"../../hooks/index.js";import{resolveSliderSize,useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{Text}from"../Text/index.js";import{sliderToneInk}from"./valueText.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const VARIANT_SIZE_MAP={inset:{sm:{trackHeight:14,thumbDiameter:10},md:{trackHeight:20,thumbDiameter:14},lg:{trackHeight:26,thumbDiameter:18}},minimal:{sm:{trackHeight:2,thumbDiameter:14},md:{trackHeight:3,thumbDiameter:18},lg:{trackHeight:4,thumbDiameter:22}},bar:{sm:{trackHeight:20,thumbDiameter:20},md:{trackHeight:28,thumbDiameter:28},lg:{trackHeight:36,thumbDiameter:36}}},INSET_RING_RATIO=.3,MIN_THUMB_TOUCH=44,clamp=(e,t,a)=>Math.min(Math.max(e,t),a),snapToStep=(e,t,a,i)=>{if(i<=0)return clamp(e,t,a);const r=Math.round((e-t)/i)*i+t,s=String(i).split(".")[1]?.length??0,n=s>0?Number(r.toFixed(s)):r;return clamp(n,t,a)},BUBBLE_GAP=2,BUBBLE_CARET=8,BUBBLE_WRAP_WIDTH=160,NO_SHADOW={shadowOpacity:0,elevation:0},defaultFormatLabel=e=>String(e),Slider=forwardRef((e,t)=>{const{min:a=0,max:i=100,step:r=1,disabled:s=!1,tone:n="primary",size:o="md",variant:l="default",showLabel:u=!1,snapThumb:c=!1,formatLabel:d=defaultFormatLabel,renderLabel:m,accessibilityLabel:h,haptic:b,style:p,containerStyle:f,trackStyle:g,fillStyle:v,thumbStyle:w,labelStyle:y,thumbPressScale:S,labelShowDuration:k,labelOpacity:C,testID:x}=e;assertValidValue("Slider","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Slider","size",e.size,["sm","md","lg"]),assertValidValue("Slider","variant",e.variant,["default","inset","minimal","bar"]);const V=useTheme(),A=useMemo(()=>{const e=resolveSliderSize(V,o);return{trackHeight:e["track-height"],thumbDiameter:e["thumb-diameter"]}},[V,o]),j=useMemo(()=>"default"===l?A:VARIANT_SIZE_MAP[l][o],[A,o,l]),M="inset"===l?j.trackHeight/2:0,_=V.settings.components.slider?.thumbPressAnimation??!1,D=S??1.1,H=k??V.motion.duration.fast,E=C??1,O=useMemo(()=>buildStyles(V,j),[V,j]),T=useMemo(()=>({damping:V.motion.spring.snappy.damping,stiffness:V.motion.spring.snappy.stiffness,mass:V.motion.spring.snappy.mass}),[V.motion.spring.snappy]),[R,I]=useState(0),W=V.colors[n],L=sliderToneInk(V,n),N=!0===e.range,[P,X]=useControllableState({value:e.value,defaultValue:e.defaultValue??(N?[a,i]:a),onChange:e.onChange}),B=useSharedValue(0),F=useSharedValue(0),z=useSharedValue(N?P[0]:P),G=useSharedValue(N?P[1]:P),J=useSharedValue(0),U=useSharedValue(0),Z=useSharedValue(1),$=useSharedValue(1),q="always"===u,K=useSharedValue(q?1:0),Q=useSharedValue(q?1:0),Y=useMemo(()=>10**(String(r).split(".")[1]?.length??0),[r]);useEffect(()=>()=>{cancelAnimation(B),cancelAnimation(F),cancelAnimation(Z),cancelAnimation($),cancelAnimation(K),cancelAnimation(Q)},[B,F,Z,$,K,Q]);const ee=useCallback((e,t)=>{const r=t-2*M;return i===a||r<=0?M:M+(e-a)/(i-a)*r},[a,i,M]),te=useCallback((e,t)=>{const s=t-2*M;if(s<=0)return a;const n=clamp((e-M)/s,0,1);return snapToStep(a+n*(i-a),a,i,r)},[a,i,r,M]),ae=useRef(!1),ie=V.motion.duration.fast,re=useRef(P);re.current=P;const se=useRef(R);se.current=R;const ne=useCallback((e=!1)=>{const t=se.current;if(t<=0)return;const place=t=>e?withTiming(t,{duration:ie,easing:Easing.out(Easing.cubic)}):t,a=re.current;if(N){const[e,i]=a,r=Math.min(e,i),s=Math.max(e,i);z.value=r,G.value=s,B.value=place(ee(r,t)),F.value=place(ee(s,t))}else{const e=a;z.value=e,G.value=e,B.value=place(ee(e,t))}},[N,ee,z,G,B,F,ie]),[oe,le]=useState(0),ue=useRef(!1),ce=useCallback(e=>{ae.current=e,e||(ue.current=!0,le(e=>e+1))},[]);useEffect(()=>{if(ae.current)return;const e=ue.current;ue.current=!1,ne(e)},[JSON.stringify(P),R,oe,ne]);const de=useCallback(e=>{const t=e.nativeEvent.layout.width;U.value=t,I(t)},[U]),me=useCallback((e,t)=>{X(N?[e,t]:e)},[N,X]),he=useCallback(()=>{const e=resolveHaptic(b,"selection");e&&triggerHaptic(e)},[b]),be=useRef(me);be.current=me;const pe=useRef(he);pe.current=he;const fe=useCallback((e,t)=>be.current(e,t),[]),ge=useCallback(()=>pe.current(),[]),ve=Math.max(0,(44-j.thumbDiameter)/2),we=ve>0?ve:void 0,ye=useCallback(e=>{const t="low"===e?B:F,n="low"===e?z:G,o="low"===e?G:z,l="low"===e?Z:$,d="low"===e?K:Q,m="low"===e,h=a,b=i,p=r,f=Y,g=N,v=D,w=_,y=!0===u,S=c,k=E,C=H,x=T,V=M,follow=e=>{"worklet";const a=U.value-2*V;if(a<=0||!Number.isFinite(e))return;const i=Math.min(Math.max(J.value+e,V),U.value-V);let r=h+(i-V)/a*(b-h);p>0&&(r=Math.round((r-h)/p)*p+h,r=Math.round(r*f)/f),r=Math.min(Math.max(r,h),b),g&&(m&&r>o.value&&(r=o.value),!m&&r<o.value&&(r=o.value)),t.value=S||b===h?b===h?V:V+(r-h)/(b-h)*a:g?m?Math.min(i,F.value):Math.max(i,B.value):i,r!==n.value&&(n.value=r,r!==h&&r!==b||runOnJS(ge)(),runOnJS(fe)(z.value,G.value))},A=Gesture.Pan().enabled(!s).minDistance(0);return(void 0===we?A:A.hitSlop(we)).onStart(()=>{"worklet";runOnJS(ce)(!0),J.value=t.value,w&&(l.value=withSpring(v,x)),y&&(d.value=withTiming(k,{duration:C,easing:Easing.out(Easing.cubic)})),runOnJS(ge)()}).onUpdate(e=>{"worklet";follow(e.translationX)}).onEnd(e=>{"worklet";follow(e.translationX),w&&(l.value=withSpring(1,x)),y&&(d.value=withTiming(0,{duration:C,easing:Easing.out(Easing.cubic)}))}).onFinalize(()=>{"worklet";runOnJS(ce)(!1)})},[s,a,i,r,Y,N,D,_,u,c,E,H,T,M,we,fe,ge,ce,B,F,z,G,Z,$,K,Q,J,U]),Se=useMemo(()=>ye("low"),[ye]),ke=useMemo(()=>ye("high"),[ye]),Ce=useCallback(e=>{if(s||N||R<=0)return;const t=clamp(e.nativeEvent.locationX,0,R),a=te(t,R);a!==z.value&&(he(),z.value=a,B.value=withTiming(ee(a,R),{duration:V.motion.duration.fast,easing:Easing.out(Easing.cubic)}),me(a,a))},[s,N,R,te,ee,me,he,B,z,V.motion.duration.fast]),xe=useCallback(e=>{if(s)return;const t="increment"===e.nativeEvent.actionName?r:-r,n=r>0?Math.round(t*Y)/Y:t;if(N){const e=Math.round((z.value+n)*Y)/Y,t=clamp(e,a,G.value);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,G.value))}else{const e=Math.round((z.value+n)*Y)/Y,t=clamp(e,a,i);t!==z.value&&(z.value=t,B.value=ee(t,R),he(),me(t,t))}},[s,r,Y,N,a,i,ee,R,B,z,G,me,he]),Ve=j.thumbDiameter/2,Ae=s?V.colors["surface-disabled"]:W,je="inset"===l?{backgroundColor:Ae,borderColor:V.colors.surface,borderWidth:Math.max(2,Math.round(.3*j.thumbDiameter)),...NO_SHADOW}:"minimal"===l?{backgroundColor:Ae,borderWidth:0}:"bar"===l?{backgroundColor:"transparent",borderWidth:0,...NO_SHADOW}:{backgroundColor:V.colors.surface,borderColor:Ae},Me=useAnimatedStyle(()=>{const e=U.value;if(e<=0)return{opacity:0,transform:[{translateX:0},{scaleX:1}]};const t=s?.55:1;if(N){const a=Math.max(0,F.value-B.value+2*M);return{opacity:t,transform:[{translateX:B.value-M},{scaleX:a/e}]}}return{opacity:t,transform:[{translateX:B.value+M-e},{scaleX:1}]}},[U,s,N,F,B,M]),De=useAnimatedStyle(()=>({transform:[{translateX:B.value-Ve},{scale:Z.value}]}),[B,Ve,Z]),He=useAnimatedStyle(()=>({transform:[{translateX:F.value-Ve},{scale:$.value}]}),[F,Ve,$]),Ee=useAnimatedStyle(()=>({opacity:K.value}),[K]),Oe=useAnimatedStyle(()=>({opacity:Q.value}),[Q]),clampDisplay=e=>clamp(e,a,i),Te=clampDisplay(N?Math.min(...P):P),Re=clampDisplay(N?Math.max(...P):P);return _jsx(View,{ref:t,style:[O.container,f,p],testID:x,accessibilityRole:"adjustable",accessibilityLabel:h,accessibilityState:{disabled:s},"aria-disabled":s,accessibilityValue:N?{min:a,max:i,now:Te,text:`${Te} to ${Re}`}:{min:a,max:i,now:Te},accessibilityActions:[{name:"increment"},{name:"decrement"}],onAccessibilityAction:xe,children:_jsx(Pressable,{onPress:Ce,disabled:s||N,style:O.trackTouch,accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:_jsxs(View,{style:O.trackWrap,onLayout:de,children:[_jsxs(View,{style:O.trackClip,pointerEvents:"none",children:[_jsx(View,{style:[O.track,{backgroundColor:s?V.colors["surface-disabled"]:V.colors.border},g]}),_jsx(Animated.View,{style:[O.fill,{backgroundColor:s?V.colors["surface-disabled"]:W},v,Me]})]}),_jsx(GestureDetector,{gesture:Se,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ve,...smoothCorners,opacity:s?.55:1},je,w,De],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Ee],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Te):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Te)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}),N?_jsx(GestureDetector,{gesture:ke,children:_jsx(Animated.View,{style:[O.thumb,{width:j.thumbDiameter,height:j.thumbDiameter,borderRadius:Ve,...smoothCorners,opacity:s?.55:1},je,w,He],accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",children:u?_jsxs(Animated.View,{style:[O.bubbleWrap,Oe],pointerEvents:"none",children:[_jsx(View,{style:[O.bubble,{backgroundColor:W}],children:m?m(Re):_jsx(Text,{variant:"caption",weight:"semibold",style:[{color:L},y],numberOfLines:1,children:d(Re)})}),_jsx(View,{style:[O.bubbleCaret,{backgroundColor:W}]})]}):null})}):null]})})})});Slider.displayName="Slider";const buildStyles=(e,t)=>{const a=e.shadow.elevated,i=Math.max(t.thumbDiameter,t.trackHeight),r=i/2+e.space.xs;return StyleSheet.create({container:{width:"100%",paddingVertical:r,justifyContent:"center"},trackTouch:{width:"100%",justifyContent:"center"},trackWrap:{width:"100%",height:i,justifyContent:"center"},trackClip:{position:"absolute",left:0,right:0,height:t.trackHeight,top:(i-t.trackHeight)/2,borderRadius:t.trackHeight/2,...smoothCorners,overflow:"hidden"},track:{position:"absolute",top:0,right:0,bottom:0,left:0,borderRadius:t.trackHeight/2,...smoothCorners},fill:{position:"absolute",top:0,left:0,width:"100%",height:t.trackHeight,borderRadius:t.trackHeight/2,...smoothCorners,transformOrigin:"left"},thumb:{position:"absolute",top:(i-t.thumbDiameter)/2,left:0,borderWidth:2,shadowColor:a.shadowColor,shadowOffset:a.shadowOffset,shadowOpacity:a.shadowOpacity,shadowRadius:a.shadowRadius,elevation:a.elevation,alignItems:"center",justifyContent:"center"},bubbleWrap:{position:"absolute",bottom:t.thumbDiameter+2,left:t.thumbDiameter/2-80,width:160,alignItems:"center"},bubbleCaret:{width:8,height:8,marginTop:-5,borderRadius:e.radius.none,...smoothCorners,transform:[{rotate:"45deg"}]},bubble:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xxs,borderRadius:e.radius.md,...smoothCorners,minWidth:36,alignItems:"center",justifyContent:"center",...Platform.select({ios:{shadowColor:e.shadow.card.shadowColor,shadowOffset:e.shadow.card.shadowOffset,shadowOpacity:e.shadow.card.shadowOpacity,shadowRadius:e.shadow.card.shadowRadius},android:{elevation:e.shadow.card.elevation},default:{}})}})};export{Slider};export default Slider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useCallback,useMemo,useRef}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useCallback,useMemo,useRef}from"react";import{Pressable,StyleSheet,TextInput,View}from"react-native";import{useControllableState}from"../../hooks/index.js";import{resolveFieldSize,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{AppIcon,renderSlotIcon}from"../AppIcon/index.js";import{FieldBase,FieldLabel,FieldMessage,hasFieldText,resolveFieldTextStyle}from"../FieldBase/FieldBase.js";import{IconButton}from"../IconButton/index.js";import{Slider}from"../Slider/index.js";import{CountingText,clampValue,sliderToneInk,snapValue,useValueDraft}from"../Slider/valueText.js";import{Text}from"../Text/index.js";import{Tooltip}from"../Tooltip/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SLIDER_FIELD_LABELS=Object.freeze({about:e=>`About ${e}`,decrease:"Decrease",increase:"Increase",fallbackName:"Value",low:e=>`${e} low`,high:e=>`${e} high`,current:e=>`${e} value`});const DEFAULT_INPUT_WIDTH=72,defaultFormatValue=e=>String(e),stepDecimals=e=>String(e).split(".")[1]?.length??0,ValueBox=({draft:e,error:l,disabled:t,width:i,accessibilityLabel:s,styles:a,style:o,testID:r})=>{const n=useTheme(),d=resolveFieldSize(n,"sm"),c=resolveFieldTextStyle(n,{disabled:t}),u=useRef(null),m=useCallback(()=>{t||u.current?.focus()},[t]);return _jsx(FieldBase,{size:"sm",focused:e.editing,disabled:t,error:l,filled:!0,width:i,onPress:m,pressFeedback:!1,paddingHorizontal:n.space.sm,gap:n.space.xs,trailing:l?_jsx(AppIcon,{name:"info-circle",size:d.icon,color:n.colors["danger-text"]}):void 0,style:o,children:_jsx(TextInput,{ref:u,style:[a.boxInput,{color:c.color,fontSize:d.text,...c.weightStyle}],value:e.text,onChangeText:e.onChangeText,onFocus:e.onFocus,onBlur:e.onBlur,onSubmitEditing:e.onBlur,editable:!t,keyboardType:"decimal-pad",returnKeyType:"done",textAlign:"center",selectionColor:n.colors.primary,accessibilityLabel:s,accessibilityState:{disabled:t},"aria-disabled":t,testID:r})})},SliderField=forwardRef((e,l)=>{const{label:t,unit:i,info:s,required:a=!1,helperText:o,error:r,min:n=0,max:d=100,step:c=1,disabled:u=!1,tone:m="primary",size:p,variant:b,haptic:x,showBubble:h=!0,showBounds:f=!0,showInput:y=!1,showStepper:g=!1,leftIcon:S,rightIcon:I,startLabel:j,endLabel:T,formatValue:V=defaultFormatValue,parseInput:_,animationDuration:w,inputWidth:F=DEFAULT_INPUT_WIDTH,labels:v,accessibilityLabel:D,style:L,labelStyle:B,boundStyle:z,sliderStyle:C,inputStyle:A,testID:k}=e;assertValidValue("SliderField","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("SliderField","size",e.size,["sm","md","lg"]),assertValidValue("SliderField","variant",e.variant,["default","inset","minimal","bar"]);const E=useMemo(()=>({...DEFAULT_SLIDER_FIELD_LABELS,...v}),[v]),M=useTheme(),$=useMemo(()=>buildStyles(M),[M]),R=w??M.motion.duration.fast,P=!0===e.range,N=!0===r||hasFieldText(r),W=stepDecimals(c),[U,H]=useControllableState({value:e.value,defaultValue:e.defaultValue??(P?[n,d]:n),onChange:e.onChange}),[q,K]=P?U:[U,d],O=clampValue(Math.min(q,K),n,d),G=clampValue(Math.max(q,K),n,d),J=useValueDraft({value:O,min:n,max:d,step:c,format:V,parse:_,onChange:e=>H(P?[Math.min(e,G),G]:e)}),Q=useValueDraft({value:G,min:n,max:d,step:c,format:V,parse:_,onChange:e=>H([O,Math.max(e,O)])}),stepBy=e=>{const l=snapValue(O+e*c,n,d,c);l!==O&&H(l)},X={color:u?M.colors["text-disabled"]:M.colors["text-muted"],size:resolveFieldSize(M,"md").icon,disabled:u},Y=[$.bubbleText,{color:sliderToneInk(M,m)}],boundText=e=>_jsx(Text,{variant:"bodySmall",style:[$.bound,{color:u?M.colors["text-disabled"]:M.colors["text-muted"]},z],children:e}),Z={min:n,max:d,step:c,disabled:u,tone:m,size:p,variant:b,haptic:x,showLabel:!!h&&"always",renderLabel:h?e=>_jsx(CountingText,{value:e,format:V,decimals:W,duration:R,style:Y,testID:k&&!P?`${k}-bubble`:void 0}):void 0,accessibilityLabel:D??t,style:C,testID:k?`${k}-slider`:void 0};return _jsxs(View,{ref:l,style:[$.container,L],testID:k,children:[t?_jsxs(View,{style:$.labelRow,children:[_jsx(FieldLabel,{required:a,style:B,children:t}),i?_jsx(Text,{variant:"caption",style:{color:M.colors["text-subtle"]},children:i}):null,s?_jsx(Tooltip,{content:s,trigger:"press",placement:"top",children:_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:E.about(t),hitSlop:8,...hitSlopMarker(8),style:$.infoButton,children:_jsx(AppIcon,{name:"info-circle",variant:"bold",size:16,color:M.colors["text-subtle"]})})}):null]}):null,_jsxs(View,{style:[$.row,h?$.rowWithBubble:null],children:[S?_jsx(View,{children:renderSlotIcon(S,X)}):null,g&&!P?_jsx(IconButton,{icon:e=>_jsx(AppIcon,{name:"minus",size:e.size,color:e.color}),onPress:()=>stepBy(-1),accessibilityLabel:E.decrease,variant:"ghost",tone:"neutral",size:"sm",disabled:u||O<=n,haptic:x,testID:k?`${k}-minus`:void 0}):null,P&&y?_jsx(ValueBox,{draft:J,error:N,disabled:u,width:F,accessibilityLabel:E.low(t??E.fallbackName),styles:$,style:A,testID:k?`${k}-input-low`:void 0}):f?boundText(j??V(n)):null,_jsx(View,{style:$.sliderWrap,children:_jsx(Slider,P?{...Z,range:!0,value:[O,G],onChange:H}:{...Z,value:O,onChange:H})}),P&&y?_jsx(ValueBox,{draft:Q,error:N,disabled:u,width:F,accessibilityLabel:E.high(t??E.fallbackName),styles:$,style:A,testID:k?`${k}-input-high`:void 0}):f?boundText(T??V(d)):null,g&&!P?_jsx(IconButton,{icon:e=>_jsx(AppIcon,{name:"add",size:e.size,color:e.color}),onPress:()=>stepBy(1),accessibilityLabel:E.increase,variant:"ghost",tone:"neutral",size:"sm",disabled:u||O>=d,haptic:x,testID:k?`${k}-plus`:void 0}):null,I?_jsx(View,{children:renderSlotIcon(I,X)}):null,!P&&y?_jsx(ValueBox,{draft:J,error:N,disabled:u,width:F,accessibilityLabel:E.current(t??E.fallbackName),styles:$,style:A,testID:k?`${k}-input`:void 0}):null]}),_jsx(FieldMessage,{text:N?r:o,error:N})]})});SliderField.displayName="SliderField";const buildStyles=e=>StyleSheet.create({container:{width:"100%"},labelRow:{flexDirection:"row",alignItems:"center",gap:e.space.xs},infoButton:{marginLeft:e.space.xxs},row:{flexDirection:"row",alignItems:"center",gap:e.space.sm},rowWithBubble:{marginTop:e.space.lg},sliderWrap:{flex:1,paddingHorizontal:e.space.sm},bound:{fontVariant:["tabular-nums"]},bubbleText:{fontVariant:["tabular-nums"]},boxInput:{flex:1,padding:e.space.none,margin:e.space.none,includeFontPadding:!1}});export{SliderField};export default SliderField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import Svg,{Circle,Path}from"react-native-svg";import{useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{formatNumber}from"@webority/mobile-core";import{forwardRef,useCallback,useMemo,useState}from"react";import{StyleSheet,View}from"react-native";import Svg,{Circle,Path}from"react-native-svg";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{finiteValues,sparklineGeometry}from"./geometry.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SPARKLINE_LABELS=Object.freeze({noData:"no data",range:(e,t,r,a)=>`from ${e} to ${t}, low ${r}, high ${a}`});const DOT_RADIUS=3,lineColor=(e,t)=>"neutral"===t?e.colors["text-muted"]:e.colors[`${t}-text`],defaultFormat=e=>formatNumber(e),Sparkline=forwardRef((e,t)=>{const{data:r,tone:a="primary",color:i,fill:o=!1,highlightLast:s=!0,height:l=32,width:n,strokeWidth:m=2,label:c,formatLabel:u=defaultFormat,accessibilityLabel:h,labels:d,style:f,testID:p}=e;assertValidValue("Sparkline","tone",e.tone,["primary","success","warning","danger","info","neutral"]);const y=useMemo(()=>({...DEFAULT_SPARKLINE_LABELS,...d}),[d]),x=useTheme(),[S,g]=useState(0),b=n??S,k=useCallback(e=>{if(void 0===n){const t=Math.round(e.nativeEvent.layout.width);g(e=>e===t?e:t)}},[n]),$=Math.max(3,m/2)+1,j=useMemo(()=>sparklineGeometry(r,b,l,$),[r,b,l,$]),L=i??lineColor(x,a),v=useMemo(()=>{if(void 0!==h)return h;const e=finiteValues(r),t=c?`${c}, `:"";if(0===e.length)return`${t}${y.noData}`;if(1===e.length)return`${t}${u(e[0])}`;const a=u(e[0]),i=u(e[e.length-1]),o=u(Math.min(...e)),s=u(Math.max(...e));return`${t}${y.range(a,i,o,s)}`},[h,r,u,c,y]);return _jsx(View,{ref:t,accessible:!0,accessibilityRole:"image",accessibilityLabel:v,testID:p,onLayout:k,style:[styles.root,void 0===n?styles.stretch:{width:n},{height:l},f],children:""===j.line?null:_jsxs(Svg,{width:b,height:l,viewBox:`0 0 ${b} ${l}`,children:[o?_jsx(Path,{d:j.area,fill:L,fillOpacity:.14,stroke:"none"}):null,_jsx(Path,{d:j.line,fill:"none",stroke:L,strokeWidth:m,strokeLinecap:"round",strokeLinejoin:"round",testID:p?`${p}-line`:void 0}),s&&j.last?_jsx(Circle,{cx:j.last.x,cy:j.last.y,r:3,fill:L,testID:p?`${p}-dot`:void 0}):null]})})});Sparkline.displayName="Sparkline";const styles=StyleSheet.create({root:{overflow:"hidden"},stretch:{alignSelf:"stretch"}});export{Sparkline};export default Sparkline;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{ActivityIndicator,Animated,Easing,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{ActivityIndicator,Animated,Easing,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{announce}from"../../utils/announce.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{blendOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{squircleHostRadius}from"../../utils/squircle.js";import{SquircleFill,useSquircle}from"../SquircleFill/SquircleFill.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_SPINNER_LABELS=Object.freeze({loading:"Loading"});const sizeMap={sm:20,md:32,lg:48},CONTAINER_RATIO=1.5,DOT_NAMES=["first","second","third"],DOT_STAGGER_MS=150,DOT_CYCLE_MS=600,DOT_GROW_SCALE=1.4,DOT_PULSE_MIN_OPACITY=.4,Dot=({size:e,color:t,delay:i,duration:n,reduced:s})=>{const r=useTheme(),o=useRef(createAnimatedValue(0)).current;useEffect(()=>{const e=Animated.loop(Animated.sequence([Animated.delay(i),Animated.timing(o,{toValue:1,duration:n/2,easing:Easing.out(Easing.quad),useNativeDriver:!0}),Animated.timing(o,{toValue:0,duration:n/2,easing:Easing.in(Easing.quad),useNativeDriver:!0})]));return e.start(),()=>{e.stop()}},[o,i,n]);const a=useMemo(()=>({grow:o.interpolate({inputRange:[0,1],outputRange:[1,1.4]}),fade:o.interpolate({inputRange:[0,1],outputRange:[.4,1]})}),[o]);return _jsx(Animated.View,{style:{width:e,height:e,borderRadius:r.radius.pill,...smoothCorners,backgroundColor:t,...s?{opacity:a.fade}:{transform:[{scale:a.grow}]}}})},Spinner=forwardRef((e,t)=>{const{size:i="md",color:n,message:s,overlay:r=!1,backdropColor:o,variant:a="circular",accessibilityLabel:l,labels:c,style:u,testID:d}=e;assertValidValue("Spinner","size",e.size,["sm","md","lg"]),assertValidValue("Spinner","variant",e.variant,["circular","dots","contained"]);const m=useMemo(()=>({...DEFAULT_SPINNER_LABELS,...c}),[c]),g="contained"===a,f=r&&!g,p=useTheme(),h=usePresenceMotion(),y=h.duration("default"),b=useRef(createAnimatedValue(0)).current;useEffect(()=>{Animated.timing(b,{toValue:1,duration:y,easing:Easing.bezier(...p.motion.ease["in-out"]),useNativeDriver:!0}).start()},[b,p,y]);const S=useMemo(()=>buildStyles(p),[p]),j=sizeMap[i],x=n??p.colors.primary,_=o??p.colors.scrim,A=useMemo(()=>{if("contained"===a){const e=Math.round(1.5*j);return _jsx(View,{style:[S.container,{width:e,height:e,borderRadius:p.radius.pill,backgroundColor:blendOf(x,.14,p.colors.surface,p.colors["bg-subtle"])}],children:_jsx(ActivityIndicator,{color:x,size:"sm"===i?"small":"large",style:{width:j,height:j}})})}if("dots"===a){const e=Math.max(6,Math.round(j/4));return _jsx(View,{style:[S.dotsRow,{gap:Math.round(e/2)}],children:DOT_NAMES.map((t,i)=>_jsx(Dot,{size:e,color:x,delay:150*i,duration:600,reduced:h.reduced},t))})}return _jsx(ActivityIndicator,{color:x,size:"sm"===i?"small":"large",style:{width:j,height:j}})},[a,i,j,x,S.dotsRow,S.container,h.reduced,p.radius.pill,p.colors.surface,p.colors["bg-subtle"]]),C=l??s??m.loading,R=useRef(C);R.current=C,useEffect(()=>{g&&announce(R.current)},[g]);const v=useSquircle(f,p.radius.lg),E=v.active&&v.size?{borderRadius:squircleHostRadius(v.size.width,v.size.height,p.radius.lg)}:null;let w=S.inlineContent;f?w=S.overlayContent:g&&(w=S.containedContent);const z=_jsxs(Animated.View,{ref:t,accessible:!0,accessibilityRole:"progressbar",accessibilityLiveRegion:g?"none":"polite",accessibilityLabel:C,accessibilityState:{busy:!0},"aria-busy":!0,testID:d,onLayout:v.onLayout,style:[w,E,{opacity:b}],children:[v.active&&v.size?_jsx(SquircleFill,{width:v.size.width,height:v.size.height,radius:p.radius.lg,fill:p.colors.surface}):null,A,s?_jsx(Text,{variant:"body",weight:"medium",style:[S.message,{marginTop:p.space.md}],numberOfLines:2,children:s}):null]});return _jsx(View,f?{pointerEvents:"auto",style:[S.overlay,{backgroundColor:_},u],children:z}:{style:[g?S.containedFill:S.inline,u],children:z})});Spinner.displayName="Spinner";const buildStyles=e=>StyleSheet.create({inline:{alignItems:"center",justifyContent:"center"},inlineContent:{alignItems:"center",justifyContent:"center"},containedFill:{flex:1,alignSelf:"stretch",alignItems:"center",justifyContent:"center",minHeight:Math.round(1.5*sizeMap.lg)+2*e.space.xl},containedContent:{alignItems:"center",justifyContent:"center",paddingHorizontal:e.space.lg},container:{alignItems:"center",justifyContent:"center"},overlay:{...StyleSheet.absoluteFill,alignItems:"center",justifyContent:"center",zIndex:1e3},overlayContent:{alignItems:"center",justifyContent:"center",backgroundColor:e.colors.surface,borderRadius:e.radius.lg,...smoothCorners,paddingHorizontal:e.space.xl,paddingVertical:e.space.xl,minWidth:140,...e.shadow.popover},dotsRow:{flexDirection:"row",alignItems:"center",justifyContent:"center"},message:{textAlign:"center"}});export{Spinner};export default Spinner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{formatPercent}from"@webority/mobile-core";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{
|
|
1
|
+
"use strict";import{formatPercent}from"@webority/mobile-core";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{AppIcon}from"../AppIcon/index.js";import{Card}from"../Card/index.js";import{IconBadge}from"../IconBadge/index.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STAT_TILE_LABELS=Object.freeze({trendUp:"up",trendDown:"down",trendFlat:"no change"});const isText=e=>"string"==typeof e||"number"==typeof e,TREND_ICON={up:"arrow-up",down:"arrow-down",flat:"minus"},TREND_SIGN={up:"+",down:"-",flat:""},percentText=e=>formatPercent(Math.abs(e),{scale:"percent",maximumFractionDigits:1}),trendFigure=e=>"number"==typeof e.value?`${TREND_SIGN[e.direction]}${percentText(e.value)}`:e.value,trendSpoken=(e,t)=>{const n=[{up:t.trendUp,down:t.trendDown,flat:t.trendFlat}[e.direction]];return"flat"!==e.direction&&n.push("number"==typeof e.value?percentText(e.value):e.value),e.period&&n.push(e.period),n.join(" ")},StatTile=forwardRef((e,t)=>{const{label:n,value:r,icon:i,iconVariant:s,tone:o="primary",caption:a,trend:l,sparkline:d,onPress:c,loading:p=!1,accessibilityLabel:x,labels:m,style:u,testID:h}=e,f=useTheme();assertValidValue("StatTile","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("StatTile","trend.direction",l?.direction,["up","down","flat"]),assertValidValue("StatTile","trend.goodWhen",l?.goodWhen,["up","down"]);const T=useMemo(()=>({...DEFAULT_STAT_TILE_LABELS,...m}),[m]),y=l?`, ${trendSpoken(l,T)}`:"",j=isText(n)?`${n}, `:"",w=x??(isText(r)?`${j}${r}${y}`:void 0),_=!!l&&l.direction===(l.goodWhen??"up"),S=l&&"flat"!==l.direction?_?"success":"danger":"secondary",g="secondary"===S?f.colors["text-muted"]:f.colors[`${S}-text`];return _jsx(Card,p?{ref:t,variant:"outline",style:u,testID:h,children:_jsxs(View,{style:[styles.row,{columnGap:f.space.md}],children:[void 0===i?null:_jsx(Skeleton,{shape:"circle",width:40,height:40}),_jsxs(View,{style:styles.text,children:[_jsx(Skeleton,{shape:"text",width:"50%",height:12}),_jsx(Skeleton,{shape:"text",width:"35%",height:24,style:{marginTop:f.space.xs}})]})]})}:{ref:t,variant:"outline",onPress:c,accessibilityLabel:w,style:u,testID:h,children:_jsxs(View,{style:[styles.row,{columnGap:f.space.md}],children:[void 0===i?null:_jsx(IconBadge,{icon:i,iconVariant:s,tone:o}),_jsxs(View,{style:styles.text,children:[_jsx(Text,{variant:"caption",color:"secondary",numberOfLines:1,children:n}),isText(r)?_jsx(Text,{variant:"h3",numberOfLines:1,children:r}):r,l?_jsxs(View,{style:[styles.trend,{columnGap:f.space.xxs}],testID:h?`${h}-trend`:void 0,children:[_jsx(View,{accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants","aria-hidden":!0,children:_jsx(AppIcon,{name:TREND_ICON[l.direction],size:"xs",color:g})}),_jsxs(Text,{variant:"caption",color:S,numberOfLines:2,style:styles.text,children:[trendFigure(l),l.period?_jsx(Text,{variant:"caption",color:"tertiary",children:` ${l.period}`}):null]})]}):null,null==a||""===a?null:isText(a)?_jsx(Text,{variant:"caption",color:"tertiary",numberOfLines:1,children:a}):a,null==d?null:_jsx(View,{style:{marginTop:f.space.sm},children:d})]})]})})});StatTile.displayName="StatTile";const styles=StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},text:{flex:1,minWidth:0},trend:{flexDirection:"row",alignItems:"center"}});export{StatTile};export default StatTile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{deriveToneInk}from"../../theme/toneInk.js";import{
|
|
1
|
+
"use strict";import{forwardRef,useMemo}from"react";import{StyleSheet,View}from"react-native";import{useTheme}from"../../theme/index.js";import{deriveToneInk}from"../../theme/toneInk.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{tintOf}from"../../utils/color.js";import{smoothCorners}from"../../utils/corners.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const sizeMap={sm:{height:22,paddingX:"sm",dot:5,gap:"xs"},md:{height:24,paddingX:"md",dot:6,gap:"xs"}},sizeFor=(e,t)=>{const s=sizeMap[t];return{height:s.height,paddingH:e.space[s.paddingX],dot:s.dot,gap:e.space[s.gap]}},SOFT_FILL_OPACITY=.14,SOFT_BORDER_OPACITY=.4,BORDER_WIDTH=1,toneFor=(e,t)=>{const{colors:s}=e;switch(t){case"success":return{base:s.success,on:s["on-success"],ink:s["success-text"],soft:s["success-soft"]};case"warning":return{base:s.warning,on:s["on-warning"],ink:s["warning-text"],soft:s["warning-soft"]};case"danger":return{base:s.danger,on:s["on-danger"],ink:s["danger-text"],soft:s["danger-soft"]};case"info":return{base:s.info,on:s["on-info"],ink:s["info-text"],soft:s["info-soft"]};case"primary":return{base:s.primary,on:s["on-primary"],ink:s["primary-text"],soft:s["primary-soft"]};default:return{base:s["text-muted"],on:s["on-neutral-strong"],ink:s["text-muted"],soft:s.border}}},isHex=e=>"string"==typeof e&&/^#[0-9a-f]{6}$/i.test(e),paletteFor=(e,t,s,a)=>{const o=isHex(a),{base:r,on:n,ink:i,soft:l}=o?{base:a,on:e.colors["text-inverse"],ink:deriveToneInk(a,[e.colors.bg,e.colors["bg-subtle"],e.colors["bg-muted"]],e.mode),soft:tintOf(a,.14,e.colors["bg-subtle"])}:toneFor(e,t),d=!o&&"neutral"===t,u=d?e.colors["bg-muted"]:tintOf(r,.14,e.colors["bg-subtle"]),g=d?e.colors.border:tintOf(r,.4,r);switch(s){case"solid":return{fill:r,border:r,text:n,dot:n};case"outline":return{fill:"transparent",border:d?g:r,text:i,dot:r};case"flat":return{fill:u,border:"transparent",text:i,dot:r};case"ghost":return{fill:"transparent",border:"transparent",text:i,dot:r};case"filled":return{fill:l,border:"transparent",text:i,dot:r};default:return{fill:u,border:g,text:i,dot:r}}},StatusBadge=forwardRef((e,t)=>{const{label:s,tone:a="neutral",variant:o="soft",size:r="md",ink:n="tone",weight:i="semibold",padding:l="default",dot:d=!1,color:u,loading:g=!1,accessibilityLabel:c,style:f,textStyle:m,testID:p}=e;assertValidValue("StatusBadge","tone",e.tone,["success","warning","danger","info","primary","neutral"]),assertValidValue("StatusBadge","variant",e.variant,["solid","soft","outline","ghost","flat","filled"]),assertValidValue("StatusBadge","size",e.size,["sm","md"]),assertValidValue("StatusBadge","ink",e.ink,["tone","primary"]),assertValidValue("StatusBadge","weight",e.weight,["semibold","bold"]),assertValidValue("StatusBadge","padding",e.padding,["default","sm","md"]);const b=useTheme(),x=sizeFor(b,r),h=useMemo(()=>paletteFor(b,a,o,u),[b,a,o,u]),S="primary"===n&&"solid"!==o?b.colors["text-body"]:h.text,y="default"===l?{minHeight:x.height,paddingHorizontal:x.paddingH}:{paddingHorizontal:b.space[l],paddingVertical:b.space.xs},k="filled"===o?0:1;return g?_jsx(StatusBadgeSkeleton,{...e}):_jsxs(View,{ref:t,accessible:!0,accessibilityRole:"text",accessibilityLabel:c??s,testID:p,style:[styles.base,{...y,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:h.fill,borderColor:h.border,borderWidth:k},f],children:[d?_jsx(View,{testID:"status-badge-dot",style:{width:x.dot,height:x.dot,borderRadius:x.dot/2,marginRight:x.gap,backgroundColor:h.dot}}):null,_jsx(Text,{variant:"sm"===r?"caption":"bodySmall",weight:i,style:[styles.label,{color:S},m],numberOfLines:1,children:s})]})});StatusBadge.displayName="StatusBadge";const StatusBadgeSkeleton=({label:e,size:t="md",variant:s="soft",padding:a="default",dot:o,style:r})=>{const n=useTheme(),i=sizeFor(n,t),l=Math.max(32,Math.min(120,6.5*(e??"").length))+2*("default"===a?i.paddingH:n.space[a])+(o?i.dot+i.gap:0),d="default"===a?i.height:Math.round(n.text["sm"===t?"xs":"sm"].size*n.leading.body)+2*n.space.xs+2*("filled"===s?0:1);return _jsx(Skeleton,{width:l,height:d,radius:d/2,style:[styles.skeleton,r]})};StatusBadgeSkeleton.displayName="StatusBadgeSkeleton",StatusBadge.Skeleton=StatusBadgeSkeleton;const styles=StyleSheet.create({base:{alignSelf:"flex-start",flexDirection:"row",alignItems:"center",justifyContent:"center"},label:{textAlign:"center",includeFontPadding:!1,textAlignVertical:"center"},skeleton:{alignSelf:"flex-start"}});export{StatusBadge};export default StatusBadge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{warnInvalidValue}from"../../utils/warnInvalidValue.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STEPPER_LABELS=Object.freeze({step:(e,t,s,i)=>`Step ${e} of ${t}, ${s}, ${i}`,statusComplete:"complete",statusActive:"active",statusUpcoming:"upcoming",progressStep:(e,t)=>`Progress: step ${e} of ${t}`,progressDone:(e,t)=>`Progress: ${e} of ${t} steps done`,captionStep:(e,t,s)=>`Step ${e} of ${t}${s?` · ${s}`:""}`,captionDone:(e,t)=>`${e} of ${t} done`});const CIRCLE_SIZE=24,SEGMENT_HEIGHT=4,PULSE_SIZE=32,PULSE_DURATION=1100,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},toneOnColorFor=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];default:return e.colors["on-primary"]}},statusWordFor=(e,t)=>{switch(t){case"complete":return e.statusComplete;case"active":return e.statusActive;default:return e.statusUpcoming}},StepCircle=({index:e,step:t,status:s,toneColor:i,upcomingColor:o,upcomingFillColor:r,textOnColor:l,upcomingTextColor:n,interactive:a,canPress:c,totalSteps:u,onPress:p,pulseEnabled:d,labels:m,circleStyles:h,circleSlotStyle:g})=>{const y="active"===s,b=useTheme(),x=useRef(createAnimatedValue(1)).current,S=useRef(createAnimatedValue(.5)).current;useEffect(()=>{if(!y||!d)return x.setValue(1),void S.setValue(0);const e=Animated.loop(Animated.parallel([Animated.sequence([Animated.timing(x,{toValue:1.4,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(x,{toValue:1,duration:0,useNativeDriver:!0})]),Animated.sequence([Animated.timing(S,{toValue:0,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(S,{toValue:.5,duration:0,useNativeDriver:!0})])]));return e.start(),()=>e.stop()},[y,x,S,d]);const w="upcoming"===s?r:i,f="upcoming"===s?o:i,v="upcoming"===s?n:l,C="complete"===s,j=m.step(e+1,u,t.label,statusWordFor(m,s)),_=_jsxs(View,{style:h.relative,children:[y&&d?_jsx(Animated.View,{pointerEvents:"none",style:[h.pulse,{width:32,height:32,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:i,opacity:S,transform:[{scale:x}]}]}):null,_jsx(View,{style:[h.circle,{width:24,height:24,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:w,borderColor:f},g],children:t.icon?t.icon:_jsx(Text,C?{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:"✓"}:{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:e+1})})]});return a?_jsx(Pressable,{onPress:()=>p(e),disabled:!c,accessibilityRole:"button",accessibilityLabel:j,accessibilityState:{selected:y,disabled:!c},"aria-selected":y,"aria-disabled":!c,hitSlop:8,...hitSlopMarker(8),children:_}):_jsx(View,{accessibilityRole:"text",accessibilityLabel:j,accessibilityState:{selected:y},"aria-selected":y,children:_})},buildCircleStyles=()=>StyleSheet.create({relative:{alignItems:"center",justifyContent:"center"},pulse:{position:"absolute"},circle:{borderWidth:2,alignItems:"center",justifyContent:"center"},glyph:{includeFontPadding:!1}}),Stepper=forwardRef((e,t)=>{const{steps:s,activeStep:i,defaultActiveStep:o=0,pressMode:r="none",onStepPress:l,onActiveStepChange:n,variant:a="horizontal",tone:c="primary",formatCaption:u,showCaption:p=!0,loading:d=!1,labels:m,accessibilityLabel:h,style:g,containerStyle:y,circleStyle:b,labelStyle:x,connectorStyle:S,haptic:w,testID:f}=e;warnInvalidValue("Stepper","variant",e.variant,["horizontal","vertical","segmented"]),warnInvalidValue("Stepper","tone",e.tone,["primary","success","warning","danger","info","neutral"]),warnInvalidValue("Stepper","pressMode",e.pressMode,["none","back","select"]);const v=useMemo(()=>({...DEFAULT_STEPPER_LABELS,...m}),[m]),C=useTheme(),j=C.settings.components.stepper?.pulseAnimation??!1,_=resolveHaptic(w,"selection"),V=useMemo(()=>buildStyles(C),[C]),k=useMemo(()=>buildCircleStyles(),[]),R=toneColorFor(C,c),I=C.colors.border,A=C.colors.bg,E=C.colors["text-muted"],L=toneOnColorFor(C,c),T=s.length,D="none"!==r,P=void 0!==i,[F,$]=useState(o),M=P?i:F,B=null==M||M<0?null:M,O=s.map((e,t)=>(e=>null===B?"upcoming":e<B?"complete":e===B?"active":"upcoming")(t)),N=O.filter(e=>"upcoming"!==e).length,U=O.filter(e=>"complete"===e).length,canPressStatus=e=>"back"===r?"complete"===e:D,handleStepPress=e=>{if(!canPressStatus(O[e]))return;_&&triggerHaptic(_),l?.(e);const t="select"===r&&e===B?null:e;P||$(t),n?.(t)},H=useRef(createAnimatedValue(N)).current,z=useRef(N);useEffect(()=>{const e=z.current;if(e===N)return;z.current=N;const t=Animated.timing(H,{toValue:N,duration:C.motion.duration.default*Math.abs(N-e),easing:Easing.linear,useNativeDriver:!1});return t.start(),()=>t.stop()},[N,H,C.motion]);const sliceOf=e=>H.interpolate({inputRange:[e,e+1],outputRange:["0%","100%"],extrapolate:"clamp"}),W=T<=1?"0%":H.interpolate({inputRange:[1,T],outputRange:["0%","100%"],extrapolate:"clamp"}),G=null!==B&&B<T?B:null,q=h??(null!==G?v.progressStep(G+1,T):v.progressDone(U,T)),[Z,J]=useState(0),K=T>0&&Z>0?Z/(2*T):0,Q=_jsx(View,{ref:t,style:[V.container,y,g],testID:f,accessibilityRole:"progressbar",accessibilityLabel:q,accessibilityValue:{min:0,max:T,now:N},children:"segmented"===a?(()=>{const e=null!==G?s[G]:void 0,t=p?u?u(G,T,e):null!==G?v.captionStep(G+1,T,e?.label):v.captionDone(U,T):"";return _jsxs(View,{children:[p?_jsx(Text,{variant:"bodySmall",style:[V.sCaption,{marginBottom:C.space.sm},x],numberOfLines:1,children:t}):null,_jsx(View,{style:V.sRow,children:s.map((e,t)=>{const s=O[t],i=v.step(t+1,T,e.label,statusWordFor(v,s)),o=_jsx(View,{testID:f?`${f}-segment-${t}`:void 0,style:[V.sTrack,{backgroundColor:I},S],children:_jsx(Animated.View,{style:[V.sFill,{backgroundColor:R,width:sliceOf(t)}]})});if(D){const r=canPressStatus(s);return _jsx(Pressable,{style:V.sItem,onPress:()=>handleStepPress(t),disabled:!r,accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:"active"===s,disabled:!r},"aria-selected":"active"===s,"aria-disabled":!r,hitSlop:{top:12,bottom:12},...hitSlopMarker({top:12,bottom:12}),children:o},e.key)}return _jsx(View,{style:V.sItem,accessibilityRole:"text",accessibilityLabel:i,accessibilityState:{selected:"active"===s},"aria-selected":"active"===s,children:o},e.key)})})]})})():"vertical"===a?_jsx(View,{style:V.vCol,children:s.map((e,t)=>{const s=O[t],i=t===T-1;return _jsxs(View,{style:V.vRow,children:[_jsxs(View,{style:V.vLeft,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:I,upcomingFillColor:A,onPressColor:R,textOnColor:L,upcomingTextColor:E,interactive:D,canPress:canPressStatus(s),totalSteps:T,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),i?null:_jsxs(View,{style:[V.vConnectorContainer,S],children:[_jsx(View,{style:[V.vConnectorTrack,{backgroundColor:I}]}),_jsx(Animated.View,{style:[V.vConnectorFill,{backgroundColor:R,height:sliceOf(t+1)}]})]})]}),_jsxs(View,{style:V.vBody,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[V.vLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "}),e.description?_jsx(Text,{variant:"bodySmall",style:V.vDescription,numberOfLines:3,children:e.description}):null]})]},e.key)})}):_jsxs(View,{style:V.hRow,onLayout:e=>J(e.nativeEvent.layout.width),children:[_jsxs(View,{pointerEvents:"none",style:[V.hConnectorContainer,{left:K,right:K},S],children:[_jsx(View,{style:[V.hConnectorTrack,{backgroundColor:I}]}),_jsx(Animated.View,{style:[V.hConnectorFill,{backgroundColor:R,width:W}]})]}),s.map((e,t)=>{const s=O[t];return _jsxs(View,{style:V.hStepItem,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:I,upcomingFillColor:A,onPressColor:R,textOnColor:L,upcomingTextColor:E,interactive:D,canPress:canPressStatus(s),totalSteps:T,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),_jsx(Text,{variant:"caption",style:[V.hLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "})]},e.key)})]})});return d?_jsx(StepperSkeleton,{...e}):Q});Stepper.displayName="Stepper";const StepperSkeleton=({steps:e,variant:t="horizontal",showCaption:s=!0,containerStyle:i,style:o,testID:r})=>{const l=useTheme(),n=useMemo(()=>buildStyles(l),[l]),a=useMemo(()=>buildSkeletonStyles(l),[l]),c=e.length||3;return"segmented"===t?_jsxs(View,{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(Skeleton,{shape:"text",width:"45%",height:14,style:{marginBottom:l.space.sm}}):null,_jsx(View,{style:n.sRow,children:Array.from({length:c}).map((e,t)=>_jsx(View,{style:n.sItem,children:_jsx(Skeleton,{width:"100%",height:4,radius:"pill"})},`sk-step-${t}`))})]}):_jsx(View,"vertical"===t?{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsx(View,{style:a.vCol,children:Array.from({length:c}).map((e,t)=>{const s=t===c-1;return _jsxs(View,{style:a.vRow,children:[_jsxs(View,{style:[a.vLeft,{width:32}],children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),s?null:_jsx(Skeleton,{width:2,height:36})]}),_jsxs(View,{style:a.vBody,children:[_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:l.space.xs}}),_jsx(Skeleton,{shape:"text",width:"80%",height:12})]})]},`sk-step-${t}`)})})}:{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:n.hRow,children:[_jsx(View,{pointerEvents:"none",style:[n.hConnectorContainer,{left:50/c+"%",right:50/c+"%"}],children:_jsx(Skeleton,{width:"100%",height:2,radius:"pill"})}),Array.from({length:c}).map((e,t)=>_jsxs(View,{style:n.hStepItem,children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),_jsx(Skeleton,{shape:"text",width:"80%",height:12,style:{marginTop:l.space.xs}})]},`sk-step-${t}`))]})})};StepperSkeleton.displayName="StepperSkeleton",Stepper.Skeleton=StepperSkeleton;const buildSkeletonStyles=e=>StyleSheet.create({vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center"},vBody:{flex:1,paddingLeft:e.space.md,paddingBottom:e.space.lg}}),buildStyles=e=>StyleSheet.create({container:{width:"100%"},hRow:{flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",position:"relative"},hConnectorContainer:{position:"absolute",top:11,height:2,flexDirection:"row",alignItems:"center"},hConnectorTrack:{position:"absolute",left:0,right:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hConnectorFill:{position:"absolute",left:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hStepItem:{alignItems:"center",flex:1},hLabel:{marginTop:e.space.xs,textAlign:"center"},vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center",alignSelf:"stretch",width:32},vConnectorContainer:{flex:1,width:2,minHeight:32,position:"relative",alignSelf:"center"},vConnectorTrack:{position:"absolute",top:0,bottom:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vConnectorFill:{position:"absolute",top:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vBody:{flex:1,paddingLeft:e.space.sm,paddingBottom:e.space.md},vLabel:{marginBottom:e.space.xxs},vDescription:{},sCaption:{includeFontPadding:!1},sRow:{flexDirection:"row",columnGap:e.space.xs},sItem:{flex:1},sTrack:{height:4,borderRadius:e.radius.pill,overflow:"hidden"},sFill:{height:4,borderRadius:e.radius.pill}});export{Stepper};export default Stepper;
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,Pressable,StyleSheet,View}from"react-native";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{Skeleton}from"../Skeleton/index.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const DEFAULT_STEPPER_LABELS=Object.freeze({step:(e,t,s,i)=>`Step ${e} of ${t}, ${s}, ${i}`,statusComplete:"complete",statusActive:"active",statusUpcoming:"upcoming",progressStep:(e,t)=>`Progress: step ${e} of ${t}`,progressDone:(e,t)=>`Progress: ${e} of ${t} steps done`,captionStep:(e,t,s)=>`Step ${e} of ${t}${s?` · ${s}`:""}`,captionDone:(e,t)=>`${e} of ${t} done`});const CIRCLE_SIZE=24,SEGMENT_HEIGHT=4,PULSE_SIZE=32,PULSE_DURATION=1100,toneColorFor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"danger":return e.colors.danger;case"info":return e.colors.info;case"neutral":return e.colors.neutral;default:return e.colors.primary}},toneOnColorFor=(e,t)=>{switch(t){case"success":return e.colors["on-success"];case"warning":return e.colors["on-warning"];case"danger":return e.colors["on-danger"];case"info":return e.colors["on-info"];case"neutral":return e.colors["on-neutral"];default:return e.colors["on-primary"]}},statusWordFor=(e,t)=>{switch(t){case"complete":return e.statusComplete;case"active":return e.statusActive;default:return e.statusUpcoming}},StepCircle=({index:e,step:t,status:s,toneColor:i,upcomingColor:o,upcomingFillColor:r,textOnColor:l,upcomingTextColor:n,interactive:a,canPress:c,totalSteps:u,onPress:p,pulseEnabled:d,labels:m,circleStyles:h,circleSlotStyle:g})=>{const y="active"===s,b=useTheme(),x=useRef(createAnimatedValue(1)).current,S=useRef(createAnimatedValue(.5)).current;useEffect(()=>{if(!y||!d)return x.setValue(1),void S.setValue(0);const e=Animated.loop(Animated.parallel([Animated.sequence([Animated.timing(x,{toValue:1.4,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(x,{toValue:1,duration:0,useNativeDriver:!0})]),Animated.sequence([Animated.timing(S,{toValue:0,duration:1100,easing:Easing.out(Easing.ease),useNativeDriver:!0}),Animated.timing(S,{toValue:.5,duration:0,useNativeDriver:!0})])]));return e.start(),()=>e.stop()},[y,x,S,d]);const f="upcoming"===s?r:i,w="upcoming"===s?o:i,v="upcoming"===s?n:l,C="complete"===s,j=m.step(e+1,u,t.label,statusWordFor(m,s)),_=_jsxs(View,{style:h.relative,children:[y&&d?_jsx(Animated.View,{pointerEvents:"none",style:[h.pulse,{width:32,height:32,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:i,opacity:S,transform:[{scale:x}]}]}):null,_jsx(View,{style:[h.circle,{width:24,height:24,borderRadius:b.radius.pill,...smoothCorners,backgroundColor:f,borderColor:w},g],children:t.icon?t.icon:_jsx(Text,C?{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:"✓"}:{variant:"bodySmall",weight:"semibold",style:[h.glyph,{color:v}],children:e+1})})]});return a?_jsx(Pressable,{onPress:()=>p(e),disabled:!c,accessibilityRole:"button",accessibilityLabel:j,accessibilityState:{selected:y,disabled:!c},"aria-selected":y,"aria-disabled":!c,hitSlop:8,...hitSlopMarker(8),children:_}):_jsx(View,{accessibilityRole:"text",accessibilityLabel:j,accessibilityState:{selected:y},"aria-selected":y,children:_})},buildCircleStyles=()=>StyleSheet.create({relative:{alignItems:"center",justifyContent:"center"},pulse:{position:"absolute"},circle:{borderWidth:2,alignItems:"center",justifyContent:"center"},glyph:{includeFontPadding:!1}}),Stepper=forwardRef((e,t)=>{const{steps:s,activeStep:i,defaultActiveStep:o=0,pressMode:r="none",onStepPress:l,onActiveStepChange:n,variant:a="horizontal",tone:c="primary",formatCaption:u,showCaption:p=!0,loading:d=!1,labels:m,accessibilityLabel:h,style:g,containerStyle:y,circleStyle:b,labelStyle:x,connectorStyle:S,haptic:f,testID:w}=e;assertValidValue("Stepper","variant",e.variant,["horizontal","vertical","segmented"]),assertValidValue("Stepper","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Stepper","pressMode",e.pressMode,["none","back","select"]);const v=useMemo(()=>({...DEFAULT_STEPPER_LABELS,...m}),[m]),C=useTheme(),j=C.settings.components.stepper?.pulseAnimation??!1,_=resolveHaptic(f,"selection"),V=useMemo(()=>buildStyles(C),[C]),k=useMemo(()=>buildCircleStyles(),[]),R=toneColorFor(C,c),A=C.colors.border,E=C.colors.bg,L=C.colors["text-muted"],T=toneOnColorFor(C,c),D=s.length,I="none"!==r,P=void 0!==i,[F,$]=useState(o),M=P?i:F,B=null==M||M<0?null:M,O=s.map((e,t)=>(e=>null===B?"upcoming":e<B?"complete":e===B?"active":"upcoming")(t)),N=O.filter(e=>"upcoming"!==e).length,U=O.filter(e=>"complete"===e).length,canPressStatus=e=>"back"===r?"complete"===e:I,handleStepPress=e=>{if(!canPressStatus(O[e]))return;_&&triggerHaptic(_),l?.(e);const t="select"===r&&e===B?null:e;P||$(t),n?.(t)},H=useRef(createAnimatedValue(N)).current,z=useRef(N);useEffect(()=>{const e=z.current;if(e===N)return;z.current=N;const t=Animated.timing(H,{toValue:N,duration:C.motion.duration.default*Math.abs(N-e),easing:Easing.linear,useNativeDriver:!1});return t.start(),()=>t.stop()},[N,H,C.motion]);const sliceOf=e=>H.interpolate({inputRange:[e,e+1],outputRange:["0%","100%"],extrapolate:"clamp"}),W=D<=1?"0%":H.interpolate({inputRange:[1,D],outputRange:["0%","100%"],extrapolate:"clamp"}),G=null!==B&&B<D?B:null,q=h??(null!==G?v.progressStep(G+1,D):v.progressDone(U,D)),[Z,J]=useState(0),K=D>0&&Z>0?Z/(2*D):0,Q=_jsx(View,{ref:t,style:[V.container,y,g],testID:w,accessibilityRole:"progressbar",accessibilityLabel:q,accessibilityValue:{min:0,max:D,now:N},children:"segmented"===a?(()=>{const e=null!==G?s[G]:void 0,t=p?u?u(G,D,e):null!==G?v.captionStep(G+1,D,e?.label):v.captionDone(U,D):"";return _jsxs(View,{children:[p?_jsx(Text,{variant:"bodySmall",style:[V.sCaption,{marginBottom:C.space.sm},x],numberOfLines:1,children:t}):null,_jsx(View,{style:V.sRow,children:s.map((e,t)=>{const s=O[t],i=v.step(t+1,D,e.label,statusWordFor(v,s)),o=_jsx(View,{testID:w?`${w}-segment-${t}`:void 0,style:[V.sTrack,{backgroundColor:A},S],children:_jsx(Animated.View,{style:[V.sFill,{backgroundColor:R,width:sliceOf(t)}]})});if(I){const r=canPressStatus(s);return _jsx(Pressable,{style:V.sItem,onPress:()=>handleStepPress(t),disabled:!r,accessibilityRole:"button",accessibilityLabel:i,accessibilityState:{selected:"active"===s,disabled:!r},"aria-selected":"active"===s,"aria-disabled":!r,hitSlop:{top:12,bottom:12},...hitSlopMarker({top:12,bottom:12}),children:o},e.key)}return _jsx(View,{style:V.sItem,accessibilityRole:"text",accessibilityLabel:i,accessibilityState:{selected:"active"===s},"aria-selected":"active"===s,children:o},e.key)})})]})})():"vertical"===a?_jsx(View,{style:V.vCol,children:s.map((e,t)=>{const s=O[t],i=t===D-1;return _jsxs(View,{style:V.vRow,children:[_jsxs(View,{style:V.vLeft,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:A,upcomingFillColor:E,onPressColor:R,textOnColor:T,upcomingTextColor:L,interactive:I,canPress:canPressStatus(s),totalSteps:D,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),i?null:_jsxs(View,{style:[V.vConnectorContainer,S],children:[_jsx(View,{style:[V.vConnectorTrack,{backgroundColor:A}]}),_jsx(Animated.View,{style:[V.vConnectorFill,{backgroundColor:R,height:sliceOf(t+1)}]})]})]}),_jsxs(View,{style:V.vBody,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[V.vLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "}),e.description?_jsx(Text,{variant:"bodySmall",style:V.vDescription,numberOfLines:3,children:e.description}):null]})]},e.key)})}):_jsxs(View,{style:V.hRow,onLayout:e=>J(e.nativeEvent.layout.width),children:[_jsxs(View,{pointerEvents:"none",style:[V.hConnectorContainer,{left:K,right:K},S],children:[_jsx(View,{style:[V.hConnectorTrack,{backgroundColor:A}]}),_jsx(Animated.View,{style:[V.hConnectorFill,{backgroundColor:R,width:W}]})]}),s.map((e,t)=>{const s=O[t];return _jsxs(View,{style:V.hStepItem,children:[_jsx(StepCircle,{index:t,step:e,status:s,toneColor:R,upcomingColor:A,upcomingFillColor:E,onPressColor:R,textOnColor:T,upcomingTextColor:L,interactive:I,canPress:canPressStatus(s),totalSteps:D,onPress:handleStepPress,pulseEnabled:j,labels:v,circleStyles:k,circleSlotStyle:b}),_jsx(Text,{variant:"caption",style:[V.hLabel,{color:"upcoming"===s?C.colors["text-subtle"]:C.colors["text-body"]},x],numberOfLines:1,children:e?.label??" "})]},e.key)})]})});return d?_jsx(StepperSkeleton,{...e}):Q});Stepper.displayName="Stepper";const StepperSkeleton=({steps:e,variant:t="horizontal",showCaption:s=!0,containerStyle:i,style:o,testID:r})=>{const l=useTheme(),n=useMemo(()=>buildStyles(l),[l]),a=useMemo(()=>buildSkeletonStyles(l),[l]),c=e.length||3;return"segmented"===t?_jsxs(View,{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:[s?_jsx(Skeleton,{shape:"text",width:"45%",height:14,style:{marginBottom:l.space.sm}}):null,_jsx(View,{style:n.sRow,children:Array.from({length:c}).map((e,t)=>_jsx(View,{style:n.sItem,children:_jsx(Skeleton,{width:"100%",height:4,radius:"pill"})},`sk-step-${t}`))})]}):_jsx(View,"vertical"===t?{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsx(View,{style:a.vCol,children:Array.from({length:c}).map((e,t)=>{const s=t===c-1;return _jsxs(View,{style:a.vRow,children:[_jsxs(View,{style:[a.vLeft,{width:32}],children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),s?null:_jsx(Skeleton,{width:2,height:36})]}),_jsxs(View,{style:a.vBody,children:[_jsx(Skeleton,{shape:"text",width:"55%",height:16,style:{marginBottom:l.space.xs}}),_jsx(Skeleton,{shape:"text",width:"80%",height:12})]})]},`sk-step-${t}`)})})}:{style:[n.container,i,o],testID:r,accessibilityRole:"progressbar",accessibilityState:{busy:!0},"aria-busy":!0,children:_jsxs(View,{style:n.hRow,children:[_jsx(View,{pointerEvents:"none",style:[n.hConnectorContainer,{left:50/c+"%",right:50/c+"%"}],children:_jsx(Skeleton,{width:"100%",height:2,radius:"pill"})}),Array.from({length:c}).map((e,t)=>_jsxs(View,{style:n.hStepItem,children:[_jsx(Skeleton,{shape:"circle",width:24,height:24}),_jsx(Skeleton,{shape:"text",width:"80%",height:12,style:{marginTop:l.space.xs}})]},`sk-step-${t}`))]})})};StepperSkeleton.displayName="StepperSkeleton",Stepper.Skeleton=StepperSkeleton;const buildSkeletonStyles=e=>StyleSheet.create({vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center"},vBody:{flex:1,paddingLeft:e.space.md,paddingBottom:e.space.lg}}),buildStyles=e=>StyleSheet.create({container:{width:"100%"},hRow:{flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",position:"relative"},hConnectorContainer:{position:"absolute",top:11,height:2,flexDirection:"row",alignItems:"center"},hConnectorTrack:{position:"absolute",left:0,right:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hConnectorFill:{position:"absolute",left:0,height:2,borderRadius:e.radius.pill,...smoothCorners},hStepItem:{alignItems:"center",flex:1},hLabel:{marginTop:e.space.xs,textAlign:"center"},vCol:{flexDirection:"column"},vRow:{flexDirection:"row",alignItems:"flex-start"},vLeft:{alignItems:"center",alignSelf:"stretch",width:32},vConnectorContainer:{flex:1,width:2,minHeight:32,position:"relative",alignSelf:"center"},vConnectorTrack:{position:"absolute",top:0,bottom:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vConnectorFill:{position:"absolute",top:0,width:2,borderRadius:e.radius.pill,...smoothCorners},vBody:{flex:1,paddingLeft:e.space.sm,paddingBottom:e.space.md},vLabel:{marginBottom:e.space.xxs},vDescription:{},sCaption:{includeFontPadding:!1},sRow:{flexDirection:"row",columnGap:e.space.xs},sItem:{flex:1},sTrack:{height:4,borderRadius:e.radius.pill,overflow:"hidden"},sFill:{height:4,borderRadius:e.radius.pill}});export{Stepper};export default Stepper;
|