@webority/mobile-ui 0.176.0 → 0.178.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 +10 -10
- package/dist/canvas-kit/manifest.json +6 -1
- package/dist/canvas-kit/release.json +6 -6
- package/lib/commonjs/components/AppIcon/AppIcon.js +1 -1
- package/lib/commonjs/components/AuthedImage/authedImageCache.js +1 -1
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.js +1 -1
- package/lib/commonjs/components/Screen/Screen.js +1 -1
- package/lib/commonjs/components/Toast/Toast.js +1 -1
- package/lib/commonjs/hooks/usePressAnimation.js +1 -1
- package/lib/commonjs/theme/ThemeContext.js +1 -1
- package/lib/commonjs/theme/merge.js +1 -1
- package/lib/commonjs/utils/contentPadding.js +1 -0
- package/lib/module/components/AppIcon/AppIcon.js +1 -1
- package/lib/module/components/AuthedImage/authedImageCache.js +1 -1
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +1 -1
- package/lib/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.js +1 -1
- package/lib/module/components/Screen/Screen.js +1 -1
- package/lib/module/components/Toast/Toast.js +1 -1
- package/lib/module/hooks/usePressAnimation.js +1 -1
- package/lib/module/theme/ThemeContext.js +1 -1
- package/lib/module/theme/merge.js +1 -1
- package/lib/module/utils/contentPadding.js +1 -0
- package/lib/typescript/commonjs/components/AppIcon/AppIcon.d.ts +1 -1
- package/lib/typescript/commonjs/components/AuthedImage/authedImageCache.d.ts +3 -1
- package/lib/typescript/commonjs/components/FieldBase/Chevron.d.ts +1 -2
- package/lib/typescript/commonjs/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -1
- package/lib/typescript/commonjs/components/Skeleton/SkeletonClock.d.ts +4 -5
- package/lib/typescript/commonjs/components/Toast/Toast.d.ts +0 -2
- package/lib/typescript/commonjs/hooks/usePressAnimation.d.ts +1 -7
- package/lib/typescript/commonjs/theme/ThemeContext.d.ts +2 -0
- package/lib/typescript/commonjs/utils/contentPadding.d.ts +4 -0
- package/lib/typescript/module/components/AppIcon/AppIcon.d.ts +1 -1
- package/lib/typescript/module/components/AuthedImage/authedImageCache.d.ts +3 -1
- package/lib/typescript/module/components/FieldBase/Chevron.d.ts +1 -2
- package/lib/typescript/module/components/PhoneNumberInput/PhoneNumberInput.d.ts +1 -1
- package/lib/typescript/module/components/Skeleton/SkeletonClock.d.ts +4 -5
- package/lib/typescript/module/components/Toast/Toast.d.ts +0 -2
- package/lib/typescript/module/hooks/usePressAnimation.d.ts +1 -7
- package/lib/typescript/module/theme/ThemeContext.d.ts +2 -0
- package/lib/typescript/module/utils/contentPadding.d.ts +4 -0
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{cloneElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{AppBar}from"../AppBar/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedList}from"../PagedList/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},
|
|
1
|
+
"use strict";import{cloneElement,useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,BackHandler,FlatList,StyleSheet,View}from"react-native";import{KeyboardStickyView}from"react-native-keyboard-controller";import{useSharedValue}from"react-native-reanimated";import{useSafeAreaInsets}from"react-native-safe-area-context";import{useRefreshControl}from"../../hooks/useRefreshControl.js";import{resolveFloatingActionButtonSize,useTheme}from"../../theme/index.js";import{bottomPaddingOf,topPaddingOf}from"../../utils/contentPadding.js";import{AppBar}from"../AppBar/index.js";import{KeyboardAwareScrollView}from"../KeyboardAwareScrollView/index.js";import{KeyboardToolbar}from"../KeyboardToolbar/index.js";import{PagedList}from"../PagedList/index.js";import{ScrollHostContext}from"./ScrollHost.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const DEFAULT_EDGES=["top","bottom"],SCROLL_EVENT_THROTTLE=16,noop=()=>{},buildStyles=e=>StyleSheet.create({flex:{flex:1},root:{flex:1,backgroundColor:e.colors.bg},overlay:{position:"absolute",top:0,left:0,right:0},headerRaised:{zIndex:1},footer:{backgroundColor:e.colors.bg,borderTopWidth:StyleSheet.hairlineWidth,borderTopColor:e.colors.border}});export function Screen(e){const{title:t,subtitle:o,largeTitle:n=!0,headerShadowOnScroll:r,onBack:a,rightActions:l,leading:s,trailing:i,children:d,onRefresh:c,refreshing:u=!1,footer:f,scroll:p=!0,list:m,edges:g=DEFAULT_EDGES,keyboardToolbar:h=!0,bottomInset:S=0,gutter:b,floatingAction:v,scrollRef:y,onScroll:x,contentContainerStyle:C,testID:T}=e,j=useTheme(),E=b??void 0===m,R=j.space[j.components.screen.gutter],w=E?R:0,k=useSafeAreaInsets(),A=useMemo(()=>buildStyles(j),[j]),[L]=useState(()=>new Animated.Value(0)),[O,V]=useState(0),[_,B]=useState(0),P=void 0!==a,z=useRef(a);z.current=a;const D=Boolean(t||o||a||s||i||l?.length),H=n&&void 0!==t,I=H&&(void 0!==m||p),K=I?O:0,M=D&&!I&&(r??j.settings.components.screen?.headerShadowOnScroll??!0),[F,N]=useState(!1),W=useRef(M);W.current=M;const headerGap=e=>e>0?e:D?j.space.lg:0,G=void 0!==f,{refreshControl:U}=useRefreshControl({onRefresh:c??noop,refreshing:u}),Y=c?cloneElement(U,{progressViewOffset:K}):void 0,$=useSharedValue(0),q=useSharedValue(0),J=useSharedValue(0),Q=useSharedValue(0),X=useRef(null),Z=useRef(0),ee=useRef(0),te=useMemo(()=>({top:$,bottom:q,offset:J,maxOffset:Q,scrollTo:e=>{const t=X.current;t instanceof FlatList?t.scrollToOffset({offset:e,animated:!1}):t?.scrollTo({y:e,animated:!1})}}),[$,q,J,Q]),oe=useCallback(e=>{X.current=e,"function"==typeof y?y(e):y&&(y.current=e)},[y]),ne=useCallback(()=>{Q.value=Math.max(0,Z.current-ee.current)},[Q]),re=useRef(x);re.current=x;const ae=useMemo(()=>Animated.event([{nativeEvent:{contentOffset:{y:L}}}],{useNativeDriver:!1,listener:e=>{if(J.value=e.nativeEvent.contentOffset.y,W.current){const t=e.nativeEvent.contentOffset.y>0;N(e=>e===t?e:t)}re.current?.(e)}}),[L,J]),le=useCallback(e=>{const{height:t}=e.nativeEvent.layout;V(e=>Math.max(e,t))},[]),se=useCallback(e=>{B(e.nativeEvent.layout.height)},[]);useEffect(()=>{if(!P)return;const e=BackHandler.addEventListener("hardwareBackPress",()=>(z.current?.(),!0));return()=>e.remove()},[P]);const ie=g.includes("left")?k.left:0,de=g.includes("right")?k.right:0,ce=g.includes("bottom")?k.bottom:0,ue=g.includes("top")&&!D?k.top:0,fe=j.space[j.components["floating-action-button"]["bottom-offset"]],pe=v?.props.bottomOffset??fe,me=v?resolveFloatingActionButtonSize(j,v.props.size??"md").diameter+pe+j.space.lg:0,ge=G?Math.max(0,_-k.bottom):S,he=v?cloneElement(v,{bottomOffset:pe+ge,position:v.props.position??"bottomRight"}):null,Se=G?me:Math.max(ce,v?me+k.bottom:0),be=S+Se-(G?0:ce),ve=g.filter(e=>"top"!==e&&!("bottom"===e&&G)),ye=D?_jsx(View,{style:I?A.overlay:M?A.headerRaised:void 0,onLayout:I?le:void 0,children:_jsx(AppBar,{title:t,subtitle:o,variant:H?"large":"default",scrollY:I?L:void 0,elevated:M&&F,onBack:a,rightActions:l,leading:s,trailing:i,gutter:R,testID:T?`${T}-app-bar`:void 0})}):null,xe=useCallback(()=>{const e=X.current?.getNativeScrollRef();e&&e.measureInWindow((e,t,o,n)=>{ee.current=n,$.value=t+K,q.value=t+n,ne()})},[K,$,q,ne]);useEffect(()=>{xe()},[xe]);const Ce=useCallback((e,t)=>{Z.current=t,ne()},[ne]);let Te;if(void 0!==m){const e=topPaddingOf([m.contentContainerStyle,C]);Te=_jsx(ScrollHostContext,{value:te,children:_jsx(PagedList,{...m,ref:oe,onRefresh:m.state?void 0:c,refreshing:m.state?void 0:u,progressViewOffset:K,placeholderStyle:[A.flex,{paddingTop:K+headerGap(e)}],onScroll:ae,onLayout:e=>{xe(),m.onLayout?.(e)},onContentSizeChange:(e,t)=>{Ce(e,t),m.onContentSizeChange?.(e,t)},scrollEventThrottle:16,style:A.flex,contentContainerStyle:[{paddingTop:K,paddingLeft:ie+w,paddingRight:de+w},m.contentContainerStyle,C,{paddingTop:K+headerGap(e),paddingBottom:bottomPaddingOf([m.contentContainerStyle,C])+S+Se}]})})}else Te=p?_jsx(ScrollHostContext,{value:te,children:_jsxs(KeyboardAwareScrollView,{ref:oe,refreshControl:Y,onScroll:ae,scrollEventThrottle:16,onLayout:xe,onContentSizeChange:Ce,safeAreaEdges:ve,style:A.flex,contentContainerStyle:[{paddingHorizontal:w},C,{paddingTop:K+headerGap(topPaddingOf(C))}],children:[d,be>0?_jsx(View,{style:{height:be}}):null]})}):_jsx(View,{style:[A.flex,{paddingLeft:ie+w,paddingRight:de+w},C,{paddingBottom:bottomPaddingOf(C)+S+Se}],children:d});const je=G?_jsx(KeyboardStickyView,{onLayout:se,style:[A.footer,{paddingLeft:ie+R,paddingRight:de+R,paddingBottom:ce+S}],children:f}):null;return _jsxs(View,{testID:T,style:[A.root,{paddingTop:ue}],children:[I?null:ye,Te,je,he,void 0!==m?d:null,I?ye:null,h?_jsx(KeyboardToolbar,{}):null]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{fillText,useMobileUiText}from"../../text/index.js";import{TOAST_TEXT}from"../../text/phone/toast.g.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:i,shownAt:n,runtime:a})=>{const r=useTheme(),s=usePresenceMotion(),o=s.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=useMobileUiText("toast",TOAST_TEXT),d=a?.labels,m=useMemo(()=>d??u,[d,u]),p=useMemo(()=>[{name:"dismiss",label:m.dismiss}],[m]),g=useMemo(()=>buildStyles(r),[r]),h=useMemo(()=>tintFor(r,l),[r,l]),v=useMemo(()=>inkFor(r,l),[r,l]),f=r.components.toast["icon-circle-size"],b=r.text[r.components.toast["icon-glyph-text"]].size,x=r.components.toast["tint-bar-width"],y=r.settings.components.toast?.defaultDurationMs??3e3,A=r.settings.components.toast?.enableSwipeDismiss??!0,T="top"===c?-120:120,w=useRef(createAnimatedValue(s.reduced?0:T)).current,M=useRef(createAnimatedValue(0)).current,D=useRef(createAnimatedValue(0)).current,S=useRef(!1),V="top"===c?8*t:8*-t,_=Math.max(1-.04*t,.9),R=useRef(createAnimatedValue(V)).current;useEffect(()=>{setNativeValue(R,V)},[V,R]);const C=useMemo(()=>Animated.add(w,R),[w,R]),N=void 0!==e.action,E=e.duration??y,j=E>0&&N&&"web"===Platform.OS?Math.max(E,8e3):E,P=j<=0||N&&!0===a?.screenReaderOn,k=!0===e.countdown&&!P,O=useRef(createAnimatedValue(1)).current,I=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),L=useRef({touch:!1,pan:!1,hover:!1}),H=useRef(()=>{}),B=useRef({id:e.id,totalMs:j,shownAt:n,runtime:a,persistent:P,animateBar:!1});B.current={id:e.id,totalMs:j,shownAt:n,runtime:a,persistent:P,animateBar:k&&!s.reduced};const F=useCallback(()=>{const e=I.current,t=B.current,i=L.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),n=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-n,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(O,e.remaining/t.totalMs)}const n=!(t.persistent||S.current||i.touch||i.pan||i.hover);n&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,H.current()},e.remaining),t.animateBar&&Animated.timing(O,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:nativeDriver}).start()):n||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),O.stopAnimation())},[O]),dismiss=()=>{if(S.current)return;S.current=!0,F();const t=[Animated.timing(D,{toValue:0,duration:o,easing:Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:nativeDriver})];s.reduced||t.push(Animated.timing(w,{toValue:T,duration:r.motion.duration.fast,easing:Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:nativeDriver})),Animated.parallel(t).start(()=>i(e.id))};H.current=dismiss;const z=useRef({reduced:s.reduced,fadeMs:o});z.current={reduced:s.reduced,fadeMs:o},useEffect(()=>{const e=z.current,t=e.reduced?Animated.timing(D,{toValue:1,duration:e.fadeMs,useNativeDriver:nativeDriver}):Animated.parallel([Animated.spring(w,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:e.fadeMs,useNativeDriver:nativeDriver})]);return t.start(),()=>t.stop()},[D,w]),useEffect(()=>{F()},[P,F]),useEffect(()=>()=>{const e=I.current,t=B.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),O.stopAnimation(),e.initialised&&t.totalMs>0&&!S.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[O]);const G=useCallback((e,t)=>{L.current[e]=t,F()},[F]),U=useCallback(()=>G("touch",!0),[G]),$=useCallback(e=>G("touch",(e.nativeEvent.touches?.length??0)>0),[G]),W=useCallback(()=>G("hover",!0),[G]),X=useCallback(()=>G("hover",!1),[G]),K=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>G("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(M,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(D,i)},onPanResponderTerminate:()=>{if(G("pan",!1),s.reduced)return setNativeValue(M,0),void Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start();Animated.parallel([Animated.spring(M,{toValue:0,damping:r.motion.spring.snappy.damping,stiffness:r.motion.spring.snappy.stiffness,mass:r.motion.spring.snappy.mass,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]).start()},onPanResponderRelease:(t,n)=>{if(Math.abs(n.dx)>80||Math.abs(n.vx)>.5){const t=n.dx>=0?1:-1;S.current=!0,G("pan",!1);const a=[Animated.timing(D,{toValue:0,duration:o,useNativeDriver:nativeDriver})];s.reduced||a.push(Animated.timing(M,{toValue:500*t,duration:r.motion.duration.fast,useNativeDriver:nativeDriver})),Animated.parallel(a).start(()=>i(e.id))}else G("pan",!1),s.reduced?(setNativeValue(M,0),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start()):Animated.parallel([Animated.spring(M,{toValue:0,useNativeDriver:nativeDriver}),Animated.spring(D,{toValue:1,useNativeDriver:nativeDriver})]).start()}}),[M,D,G,o,s.reduced,r.motion.duration.fast,r.motion.spring.snappy.damping,r.motion.spring.snappy.stiffness,r.motion.spring.snappy.mass,i,e.id]),Y={accessibilityActions:p,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[q,J]=useState(0),Q=useMemo(()=>O.interpolate({inputRange:[0,1],outputRange:[-q,0]}),[O,q]),Z=e.description?`${e.message}. ${e.description}`:e.message,ee=e.action&&k?`${e.action.label}, ${fillText(m.seconds,{count:Math.ceil(j/1e3)})}`:e.action?.label;return _jsxs(Animated.View,{...A?K.panHandlers:{},...N?{}:{accessible:!0,...Y},..."web"===Platform.OS?{onPointerEnter:W,onPointerLeave:X}:{},onTouchStart:U,onTouchEnd:$,onTouchCancel:$,accessibilityLabel:Z,testID:e.testID,style:[g.container,{backgroundColor:r.colors.surface,borderRadius:r.radius.lg,...smoothCorners,padding:r.space.md,...r.shadow.elevated,opacity:D,transform:[{translateY:C},{translateX:M},{scale:_}]},e.style],children:[x>0?_jsx(View,{style:[g.tintBar,{width:x,backgroundColor:h}]}):null,_jsxs(View,{style:g.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[g.iconCircle,{width:f,height:f,borderRadius:r.radius.pill,...smoothCorners,backgroundColor:`${h}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[g.iconGlyph,{color:v,fontSize:b}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:g.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:[e.textStyle,e.messageStyle],numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:g.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:ee,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...Y,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[g.actionBtn,{backgroundColor:t?r.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:h},numberOfLines:1,children:e.action.label})}):null]}),k?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>J(e.nativeEvent.layout.width),testID:"toast-countdown",style:[g.countdownTrack,{backgroundColor:`${h}22`}],children:[s.reduced?_jsx(View,{style:[g.countdownFill,{backgroundColor:h}]}):null,!s.reduced&&q>0?_jsx(Animated.View,{style:[g.countdownFill,{backgroundColor:h,transform:[{translateX:Q}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;case"neutral":return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];case"neutral":return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";case"primary":case"neutral":return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:Math.round(e.text[e.components.toast["icon-glyph-text"]].size*e.leading.heading)},textBlock:{flex:1,paddingRight:e.space.sm},description:{marginTop:e.space.xxs},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
|
|
1
|
+
"use strict";import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{Animated,Easing,PanResponder,Platform,Pressable,StyleSheet,View}from"react-native";import{usePresenceMotion}from"../../hooks/usePresenceMotion.js";import{fillText,useMobileUiText}from"../../text/index.js";import{TOAST_TEXT}from"../../text/phone/toast.g.js";import{createAnimatedValue,setNativeValue,useTheme}from"../../theme/index.js";import{assertValidValue}from"../../utils/assertValidValue.js";import{smoothCorners}from"../../utils/corners.js";import{hitSlopMarker}from"../../utils/hitSlop.js";import{nativeDriver}from"../../utils/nativeDriver.js";import{Text}from"../Text/index.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const SWIPE_DISMISS_THRESHOLD=80,SWIPE_VELOCITY_THRESHOLD=.5,STACK_OFFSET=8,STACK_SCALE_STEP=.04,DEFAULT_AUTO_DISMISS_MS=3e3,WEB_ACTION_MIN_DURATION_MS=8e3,COUNTDOWN_BAR_HEIGHT=3,ACTION_HIT_SLOP={top:10,bottom:10,left:10,right:10},Toast=({toast:e,index:t,onClose:i,shownAt:n,runtime:a})=>{const r=useTheme(),s=usePresenceMotion(),o=s.duration("fast");assertValidValue("Toast","tone",e.tone,["primary","success","warning","danger","info","neutral"]),assertValidValue("Toast","position",e.position,["top","bottom"]);const l=e.tone??"neutral",c=e.position??"bottom",u=useMobileUiText("toast",TOAST_TEXT),d=a?.labels,m=useMemo(()=>d??u,[d,u]),p=useMemo(()=>[{name:"dismiss",label:m.dismiss}],[m]),g=useMemo(()=>buildStyles(r),[r]),h=useMemo(()=>tintFor(r,l),[r,l]),v=useMemo(()=>inkFor(r,l),[r,l]),f=r.components.toast["icon-circle-size"],b=r.text[r.components.toast["icon-glyph-text"]].size,x=r.components.toast["tint-bar-width"],y=r.settings.components.toast?.defaultDurationMs??3e3,A=r.settings.components.toast?.enableSwipeDismiss??!0,T="top"===c?-120:120,w=useRef(createAnimatedValue(s.reduced?0:T)).current,M=useRef(createAnimatedValue(0)).current,D=useRef(createAnimatedValue(0)).current,V=useRef(!1),S="top"===c?8*t:8*-t,_=Math.max(1-.04*t,.9),R=useRef(createAnimatedValue(S)).current;useEffect(()=>{setNativeValue(R,S)},[S,R]);const C=useMemo(()=>Animated.add(w,R),[w,R]),N=void 0!==e.action,E=e.duration??y,j=E>0&&N&&"web"===Platform.OS?Math.max(E,8e3):E,P=j<=0||N&&!0===a?.screenReaderOn,k=!0===e.countdown&&!P,O=useRef(createAnimatedValue(1)).current,I=useRef({initialised:!1,timer:null,remaining:0,startedAt:0}),L=useRef({touch:!1,pan:!1,hover:!1}),H=useRef(()=>{}),B=useRef({id:e.id,totalMs:j,shownAt:n,runtime:a,persistent:P,animateBar:!1});B.current={id:e.id,totalMs:j,shownAt:n,runtime:a,persistent:P,animateBar:k&&!s.reduced};const F=useCallback(()=>{const e=I.current,t=B.current,i=L.current;if(!e.initialised){e.initialised=!0;const i=t.runtime?.readRemaining(t.id),n=void 0===t.shownAt?0:Date.now()-t.shownAt;e.remaining=i??(t.totalMs>0?Math.max(t.totalMs-n,0):0),t.totalMs>0&&e.remaining<t.totalMs&&setNativeValue(O,e.remaining/t.totalMs)}const n=!(t.persistent||V.current||i.touch||i.pan||i.hover);n&&null===e.timer?(e.startedAt=Date.now(),e.timer=setTimeout(()=>{e.timer=null,e.remaining=0,H.current()},e.remaining),t.animateBar&&Animated.timing(O,{toValue:0,duration:e.remaining,easing:Easing.linear,useNativeDriver:nativeDriver}).start()):n||null===e.timer||(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0),O.stopAnimation())},[O]),dismiss=()=>{if(V.current)return;V.current=!0,F();const t=[Animated.timing(D,{toValue:0,duration:o,easing:Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:nativeDriver})];s.reduced||t.push(Animated.timing(w,{toValue:T,duration:r.motion.duration.fast,easing:Easing.bezier(...r.motion.ease.accelerate),useNativeDriver:nativeDriver})),Animated.parallel(t).start(()=>i(e.id))};H.current=dismiss;const z=useRef({reduced:s.reduced,fadeMs:o});z.current={reduced:s.reduced,fadeMs:o},useEffect(()=>{const e=z.current,t=e.reduced?Animated.timing(D,{toValue:1,duration:e.fadeMs,useNativeDriver:nativeDriver}):Animated.parallel([Animated.spring(w,{toValue:0,damping:18,stiffness:180,mass:1,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:e.fadeMs,useNativeDriver:nativeDriver})]);return t.start(),()=>t.stop()},[D,w]),useEffect(()=>{F()},[P,F]),useEffect(()=>()=>{const e=I.current,t=B.current;null!==e.timer&&(clearTimeout(e.timer),e.timer=null,e.remaining=Math.max(e.remaining-(Date.now()-e.startedAt),0)),O.stopAnimation(),e.initialised&&t.totalMs>0&&!V.current&&t.runtime?.writeRemaining(t.id,e.remaining)},[O]);const G=useCallback((e,t)=>{L.current[e]=t,F()},[F]),U=useCallback(()=>G("touch",!0),[G]),$=useCallback(e=>G("touch",(e.nativeEvent.touches?.length??0)>0),[G]),W=useCallback(()=>G("hover",!0),[G]),X=useCallback(()=>G("hover",!1),[G]),K=useMemo(()=>PanResponder.create({onMoveShouldSetPanResponder:(e,t)=>Math.abs(t.dx)>Math.abs(t.dy)&&Math.abs(t.dx)>6,onPanResponderGrant:()=>G("pan",!0),onPanResponderMove:(e,t)=>{setNativeValue(M,t.dx);const i=1-.7*Math.min(Math.abs(t.dx)/200,1);setNativeValue(D,i)},onPanResponderTerminate:()=>{if(G("pan",!1),s.reduced)return setNativeValue(M,0),void Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start();Animated.parallel([Animated.spring(M,{toValue:0,damping:r.motion.spring.snappy.damping,stiffness:r.motion.spring.snappy.stiffness,mass:r.motion.spring.snappy.mass,useNativeDriver:nativeDriver}),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver})]).start()},onPanResponderRelease:(t,n)=>{if(Math.abs(n.dx)>80||Math.abs(n.vx)>.5){const t=n.dx>=0?1:-1;V.current=!0,G("pan",!1);const a=[Animated.timing(D,{toValue:0,duration:o,useNativeDriver:nativeDriver})];s.reduced||a.push(Animated.timing(M,{toValue:500*t,duration:r.motion.duration.fast,useNativeDriver:nativeDriver})),Animated.parallel(a).start(()=>i(e.id))}else G("pan",!1),s.reduced?(setNativeValue(M,0),Animated.timing(D,{toValue:1,duration:o,useNativeDriver:nativeDriver}).start()):Animated.parallel([Animated.spring(M,{toValue:0,useNativeDriver:nativeDriver}),Animated.spring(D,{toValue:1,useNativeDriver:nativeDriver})]).start()}}),[M,D,G,o,s.reduced,r.motion.duration.fast,r.motion.spring.snappy.damping,r.motion.spring.snappy.stiffness,r.motion.spring.snappy.mass,i,e.id]),Y={accessibilityActions:p,onAccessibilityAction:e=>{"dismiss"===e.nativeEvent.actionName&&dismiss()}},[q,J]=useState(0),Q=useMemo(()=>O.interpolate({inputRange:[0,1],outputRange:[-q,0]}),[O,q]),Z=e.description?`${e.message}. ${e.description}`:e.message,ee=e.action&&k?`${e.action.label}, ${fillText(m.seconds,{count:Math.ceil(j/1e3)})}`:e.action?.label;return _jsxs(Animated.View,{...A?K.panHandlers:{},...N?{}:{accessible:!0,...Y},..."web"===Platform.OS?{onPointerEnter:W,onPointerLeave:X}:{},onTouchStart:U,onTouchEnd:$,onTouchCancel:$,accessibilityLabel:Z,testID:e.testID,style:[g.container,{backgroundColor:r.colors.surface,borderRadius:r.radius.lg,...smoothCorners,padding:r.space.md,...r.shadow.elevated,opacity:D,transform:[{translateY:C},{translateX:M},{scale:_}]},e.style],children:[x>0?_jsx(View,{style:[g.tintBar,{width:x,backgroundColor:h}]}):null,_jsxs(View,{style:g.row,children:[(()=>{if(e.icon)return e.icon;const t=defaultGlyph(l);return t?_jsx(View,{style:[g.iconCircle,{width:f,height:f,borderRadius:r.radius.pill,...smoothCorners,backgroundColor:`${h}22`},e.iconCircleStyle],children:_jsx(Text,{variant:"body",style:[g.iconGlyph,{color:v,fontSize:b}],accessible:!1,children:t})}):null})(),_jsxs(View,{style:g.textBlock,children:[_jsx(Text,{variant:"body",weight:"semibold",style:e.textStyle,numberOfLines:2,children:e.message}),e.description?_jsx(Text,{variant:"bodySmall",style:g.description,numberOfLines:3,children:e.description}):null]}),e.action?_jsx(Pressable,{accessibilityRole:"button",accessibilityLabel:ee,hitSlop:ACTION_HIT_SLOP,...hitSlopMarker(ACTION_HIT_SLOP),...Y,onPress:()=>{e.action?.onPress(),dismiss()},style:({pressed:t})=>[g.actionBtn,{backgroundColor:t?r.colors["surface-pressed"]:"transparent"},e.actionButtonStyle],children:_jsx(Text,{variant:"bodySmall",weight:"semibold",style:{color:h},numberOfLines:1,children:e.action.label})}):null]}),k?_jsxs(View,{pointerEvents:"none",accessibilityElementsHidden:!0,importantForAccessibility:"no-hide-descendants",onLayout:e=>J(e.nativeEvent.layout.width),testID:"toast-countdown",style:[g.countdownTrack,{backgroundColor:`${h}22`}],children:[s.reduced?_jsx(View,{style:[g.countdownFill,{backgroundColor:h}]}):null,!s.reduced&&q>0?_jsx(Animated.View,{style:[g.countdownFill,{backgroundColor:h,transform:[{translateX:Q}]}]}):null]}):null]})},tintFor=(e,t)=>{switch(t){case"primary":return e.colors.primary;case"success":return e.colors.success;case"danger":return e.colors.danger;case"warning":return e.colors.warning;case"info":return e.colors.info;case"neutral":return e.colors["text-body"]}},inkFor=(e,t)=>{switch(t){case"primary":return e.colors["primary-text"];case"success":return e.colors["success-text"];case"danger":return e.colors["danger-text"];case"warning":return e.colors["warning-text"];case"info":return e.colors["info-text"];case"neutral":return e.colors["text-body"]}},defaultGlyph=e=>{switch(e){case"success":return"✓";case"danger":return"×";case"warning":return"!";case"info":return"i";case"primary":case"neutral":return""}},buildStyles=e=>StyleSheet.create({container:{overflow:"hidden",marginVertical:e.space.xs},tintBar:{position:"absolute",left:0,top:0,bottom:0},row:{flexDirection:"row",alignItems:"center",paddingLeft:e.space.sm},iconCircle:{alignItems:"center",justifyContent:"center",marginRight:e.space.md},iconGlyph:{fontWeight:"700",lineHeight:Math.round(e.text[e.components.toast["icon-glyph-text"]].size*e.leading.heading)},textBlock:{flex:1,paddingRight:e.space.sm},description:{marginTop:e.space.xxs},countdownTrack:{position:"absolute",left:0,right:0,bottom:0,height:3,overflow:"hidden"},countdownFill:{position:"absolute",left:0,right:0,top:0,bottom:0},actionBtn:{paddingHorizontal:e.space.sm,paddingVertical:e.space.xs,minHeight:e.components.toast["action-min-height"],borderRadius:e.radius.md,...smoothCorners,marginLeft:e.space.sm}});export{Toast};export default Toast;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useCallback,useMemo,useRef}from"react";import{Easing,Animated as RNAnimated}from"react-native";import{setNativeValue,useTheme}from"../theme/index.js";import{createAnimatedValue}from"../theme/animatedValue.js";import{nativeDriver}from"../utils/nativeDriver.js";import{usePresenceMotion}from"./usePresenceMotion.js";export const PRESS_ANIMATION_PRESETS=["scale","bounce","fade","sink","pulse","dim"];const FADE_TO=.6,DIM_TO=.7,SINK_BY=2,PULSE_TO=1.05,DEFAULT_SCALE_TO={scale:.97,bounce:.92,fade:1,sink:1,pulse:1,dim:1};export const usePressAnimation=({preset:e="scale",scaleTo:a,pressDuration:s,enabled:t=!0}={})=>{const i=useTheme(),r=usePresenceMotion(),n=useRef(createAnimatedValue(1)).current,o=useRef(createAnimatedValue(1)).current,u=useRef(createAnimatedValue(0)).current,c=r.reduced?"dim"===e?"dim":"fade":e,m=a??DEFAULT_SCALE_TO[c],l=s??r.duration("fast"),d=useCallback((e,a,s)=>RNAnimated.timing(e,{toValue:a,duration:l,easing:Easing.bezier(...s),useNativeDriver:nativeDriver}),[l]),p=useCallback((e,a,s)=>RNAnimated.spring(e,{toValue:a,damping:i.motion.spring[s].damping,stiffness:i.motion.spring[s].stiffness,mass:i.motion.spring[s].mass,useNativeDriver:nativeDriver}),[i]),f=useCallback(()=>{if(t)switch(c){case"scale":case"bounce":d(n,m,i.motion.ease["in-out"]).start();break;case"fade":d(o,.6,i.motion.ease["in-out"]).start();break;case"dim":setNativeValue(o,.7);break;case"sink":d(u,2,i.motion.ease["in-out"]).start()}},[t,c,m,n,o,u,i,d]),b=useCallback(()=>{if(t)switch(c){case"scale":p(n,1,"snappy").start();break;case"bounce":p(n,1,"bouncy").start();break;case"fade":d(o,1,i.motion.ease.decelerate).start();break;case"dim":setNativeValue(o,1);break;case"sink":p(u,0,"snappy").start()}},[t,c,n,o,u,i,d,p]),v=useCallback(()=>{t&&"pulse"===c&&RNAnimated.sequence([RNAnimated.timing(n,{toValue:1.05,duration:i.motion.duration.instant,easing:Easing.bezier(...i.motion.ease.accelerate),useNativeDriver:nativeDriver}),p(n,1,"snappy")]).start()},[t,c,n,i,p])
|
|
1
|
+
"use strict";import{useCallback,useMemo,useRef}from"react";import{Easing,Animated as RNAnimated}from"react-native";import{setNativeValue,useTheme}from"../theme/index.js";import{createAnimatedValue}from"../theme/animatedValue.js";import{nativeDriver}from"../utils/nativeDriver.js";import{usePresenceMotion}from"./usePresenceMotion.js";export const PRESS_ANIMATION_PRESETS=["scale","bounce","fade","sink","pulse","dim"];const FADE_TO=.6,DIM_TO=.7,SINK_BY=2,PULSE_TO=1.05,DEFAULT_SCALE_TO={scale:.97,bounce:.92,fade:1,sink:1,pulse:1,dim:1};export const usePressAnimation=({preset:e="scale",scaleTo:a,pressDuration:s,enabled:t=!0}={})=>{const i=useTheme(),r=usePresenceMotion(),n=useRef(createAnimatedValue(1)).current,o=useRef(createAnimatedValue(1)).current,u=useRef(createAnimatedValue(0)).current,c=r.reduced?"dim"===e?"dim":"fade":e,m=a??DEFAULT_SCALE_TO[c],l=s??r.duration("fast"),d=useCallback((e,a,s)=>RNAnimated.timing(e,{toValue:a,duration:l,easing:Easing.bezier(...s),useNativeDriver:nativeDriver}),[l]),p=useCallback((e,a,s)=>RNAnimated.spring(e,{toValue:a,damping:i.motion.spring[s].damping,stiffness:i.motion.spring[s].stiffness,mass:i.motion.spring[s].mass,useNativeDriver:nativeDriver}),[i]),f=useCallback(()=>{if(t)switch(c){case"scale":case"bounce":d(n,m,i.motion.ease["in-out"]).start();break;case"fade":d(o,.6,i.motion.ease["in-out"]).start();break;case"dim":setNativeValue(o,.7);break;case"sink":d(u,2,i.motion.ease["in-out"]).start()}},[t,c,m,n,o,u,i,d]),b=useCallback(()=>{if(t)switch(c){case"scale":p(n,1,"snappy").start();break;case"bounce":p(n,1,"bouncy").start();break;case"fade":d(o,1,i.motion.ease.decelerate).start();break;case"dim":setNativeValue(o,1);break;case"sink":p(u,0,"snappy").start()}},[t,c,n,o,u,i,d,p]),v=useCallback(()=>{t&&"pulse"===c&&RNAnimated.sequence([RNAnimated.timing(n,{toValue:1.05,duration:i.motion.duration.instant,easing:Easing.bezier(...i.motion.ease.accelerate),useNativeDriver:nativeDriver}),p(n,1,"snappy")]).start()},[t,c,n,i,p]);return{style:useMemo(()=>({transform:[{scale:n},{translateY:u}],opacity:o}),[n,u,o]),pressIn:f,pressOut:b,press:v}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{Storage}from"@webority/mobile-core";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Appearance}from"react-native";import{useReducedMotion}from"../hooks/useReducedMotion.js";import{isOneOf}from"../utils/guards.js";import{mergeBrand}from"./merge.js";import{darkTheme,lightTheme}from"./tokens.js";import{jsx as _jsx}from"react/jsx-runtime";const REDUCED_SPRING={damping:100,stiffness:1e3,mass:1},collapseMotion=e=>({...e,duration:{instant:0,fast:0,default:0,slow:0,slower:0},spring:{gentle:REDUCED_SPRING,bouncy:REDUCED_SPRING,snappy:REDUCED_SPRING}}),isPreference=e=>"light"===e||"dark"===e||"system"===e,COLOR_MODES=["light","dark"],colorModeOf=e=>isOneOf(COLOR_MODES,e)?e:"light",defaultValue={theme:lightTheme,mode:"light",preference:"system",setPreference:()=>{},toggleColorMode:()=>{}},ThemeContext=createContext(defaultValue);export const ThemeProvider=e=>{const{children:
|
|
1
|
+
"use strict";import{Storage}from"@webority/mobile-core";import{createContext,useCallback,useContext,useEffect,useMemo,useRef,useState}from"react";import{Appearance}from"react-native";import{useReducedMotion}from"../hooks/useReducedMotion.js";import{assertValidValue}from"../utils/assertValidValue.js";import{isOneOf}from"../utils/guards.js";import{mergeBrand}from"./merge.js";import{darkTheme,lightTheme}from"./tokens.js";import{jsx as _jsx}from"react/jsx-runtime";const REDUCED_SPRING={damping:100,stiffness:1e3,mass:1},collapseMotion=e=>({...e,duration:{instant:0,fast:0,default:0,slow:0,slower:0},spring:{gentle:REDUCED_SPRING,bouncy:REDUCED_SPRING,snappy:REDUCED_SPRING}}),isPreference=e=>"light"===e||"dark"===e||"system"===e,COLOR_MODES=["light","dark"],colorModeOf=e=>isOneOf(COLOR_MODES,e)?e:"light",fixedModeError=e=>new Error(`ThemeProvider: the colour mode is fixed to ${e} by the mode prop`),defaultValue={theme:lightTheme,mode:"light",preference:"system",setPreference:()=>{},toggleColorMode:()=>{}},ThemeContext=createContext(defaultValue);export const ThemeProvider=e=>{const{children:r,mode:o,initialPreference:t="system",persistKey:s,brand:n,settings:i,...d}=e;if(Object.keys(d).length>0)throw new Error("ThemeProvider takes only these props: children, mode, initialPreference, persistKey, brand, settings.");if(assertValidValue("ThemeProvider","mode",o,COLOR_MODES),void 0!==o&&(void 0!==s||void 0!==e.initialPreference))throw new Error("ThemeProvider: mode fixes the colour mode, so persistKey and initialPreference cannot be passed with it");const[m,a]=useState(t),c=useRef(!1);useEffect(()=>{if(!s||void 0!==o)return;let e=!0;return Storage.getItem(s).then(r=>{e&&!c.current&&isPreference(r)&&a(r)}),()=>{e=!1}},[s,o]);const l=useCallback(e=>{if(void 0!==o)throw fixedModeError(o);c.current=!0,a(e)},[o]);useEffect(()=>{s&&c.current&&Storage.setItem(s,m)},[s,m]);const[u,f]=useState(()=>colorModeOf(Appearance.getColorScheme()));useEffect(()=>{if(void 0!==o)return;const e=Appearance.addChangeListener(({colorScheme:e})=>{f(colorModeOf(e))});return()=>e.remove()},[o]);const h=o??("system"===m?u:m),g=useReducedMotion(),p=useMemo(()=>{const e="dark"===h?darkTheme:lightTheme,r=n||i?mergeBrand(e,n,i):e;return g?{...r,motion:collapseMotion(r.motion)}:r},[h,n,i,g]),M=useMemo(()=>({theme:p,mode:h,preference:o??m,setPreference:l,toggleColorMode:()=>{if(void 0!==o)throw fixedModeError(o);l(e=>"system"===e?"dark"===u?"light":"dark":"dark"===e?"light":"dark")}}),[p,h,m,u,l,o]);return _jsx(ThemeContext,{value:M,children:r})};export const KitThemeBridge=({mode:e,brand:r,children:o})=>{const t=useReducedMotion();if("light"!==e&&"dark"!==e)throw new Error('KitThemeBridge takes mode "light" or "dark".');const s=useMemo(()=>{const o="dark"===e?darkTheme:lightTheme,s=r?mergeBrand(o,r,void 0):o;return t?{...s,motion:collapseMotion(s.motion)}:s},[e,r,t]),n=useMemo(()=>({theme:s,mode:e,preference:e,setPreference:()=>{},toggleColorMode:()=>{}}),[s,e]);return _jsx(ThemeContext,{value:n,children:o})};export const useTheme=()=>useContext(ThemeContext).theme;export const useThemeMode=()=>{const e=useContext(ThemeContext);return{mode:e.mode,preference:e.preference,setPreference:e.setPreference,toggleColorMode:e.toggleColorMode}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{hasKey,isOneOf,isRecord,keysOf}from"../utils/guards.js";import{validateComponentTokens}from"./componentSizes.js";import{COLOR_NAMES,FONT_NAMES,RADIUS_NAMES,WEIGHT_NAMES}from"./tokens.generated.js";import{deriveSolidFill,deriveStateFills,deriveToneInk}from"./toneInk.js";const
|
|
1
|
+
"use strict";import{hasKey,isOneOf,isRecord,keysOf}from"../utils/guards.js";import{validateComponentTokens}from"./componentSizes.js";import{COLOR_NAMES,FONT_NAMES,RADIUS_NAMES,WEIGHT_NAMES}from"./tokens.generated.js";import{deriveSolidFill,deriveStateFills,deriveToneInk}from"./toneInk.js";const BRAND_KEYS=["colors","descriptions","radius","font"],COLOR_MODES=["light","dark"],FIXED_RADII=["none","pill"],RADIUS_ALLOWED="sm, md, lg, xl",SETTINGS_KEYS=["icons","gradients","textVariants","maxFontSizeMultiplier","components"],COMPONENT_SETTING_KEYS={field:{defaultVariant:!0,requiredMarker:!0},input:{defaultVariant:!0,defaultLabelMode:!0,tintLabelOnFocus:!0,shakeOnError:!0},"search-bar":{defaultVariant:!0},select:{defaultVariant:!0},"otp-input":{shakeOnError:!0},"option-sheet":{selectedMarker:!0},"profile-picker":{defaultTone:!0,defaultVariant:!0,defaultAvatarTone:!0},slider:{thumbPressAnimation:!0},rating:{pulseOnPress:!0},stepper:{pulseAnimation:!0},tooltip:{enableScaleAnimation:!0},toast:{enableSwipeDismiss:!0,defaultDurationMs:!0},button:{defaultVariant:!0,defaultSize:!0,defaultPressAnimation:!0},card:{defaultVariant:!0,defaultPadding:!0,defaultRadius:!0,defaultTitleFont:!0},"section-header":{defaultVariant:!0,defaultFlush:!0},"empty-state":{defaultSize:!0,defaultVariant:!0},screen:{tabBarFloats:!0,headerShadowOnScroll:!0}},isPlainObject=o=>"object"==typeof o&&null!==o&&!Array.isArray(o),validateBrand=o=>{if(void 0===o)return;if(!isPlainObject(o))throw new Error(`A brand is an object of colors, radius and font; got ${typeof o}.`);for(const t of Object.keys(o))if(!BRAND_KEYS.includes(t))throw new Error(`A brand sets colors, descriptions, radius and font only; ${t} is not allowed (allowed: colors, descriptions, radius, font).`);const t=o.descriptions;if(void 0!==t){if(!isPlainObject(t))throw new Error(`A brand's descriptions is an object of colour names to a description; got ${typeof t}.`);for(const o of Object.keys(t)){const e=t[o];if("string"!=typeof e||""===e)throw new Error(`description of colour ${o} must be a non-empty string.`)}}const e=o.colors;if(void 0!==e&&!isPlainObject(e))throw new Error(`A brand's colors is an object of light and dark; got ${typeof e}.`);if(isRecord(e))for(const o of Object.keys(e)){if(!COLOR_MODES.includes(o))throw new Error(`A brand sets colours under light and dark only; ${o} is not allowed (allowed: light, dark).`);const n=e[o];if(void 0===n)throw new Error(`A brand's ${o} colours are missing.`);if(!isRecord(n))throw new Error(`A brand's ${o} colours is an object of colour names; got ${typeof n}.`);for(const o of Object.keys(n)){const e=isRecord(t)&&"string"==typeof t[o];if(!isOneOf(COLOR_NAMES,o)&&!e)throw new Error(`unknown colour ${o}; allowed: ${COLOR_NAMES.join(", ")}.`);if(void 0!==n[o]&&"string"!=typeof n[o])throw new Error(`colour ${o} must be a string; got ${typeof n[o]}.`)}}const n=o.radius;if(void 0!==n){if(!isPlainObject(n))throw new Error(`A brand's radius is an object of radius names; got ${typeof n}.`);for(const o of Object.keys(n)){const t=n[o];if(!isOneOf(RADIUS_NAMES,o))throw new Error(`unknown radius ${o}; allowed: ${RADIUS_ALLOWED}.`);if(FIXED_RADII.includes(o))throw new Error(`radius ${o} is fixed by the library; allowed: ${RADIUS_ALLOWED}.`);if("number"!=typeof t||!Number.isFinite(t))throw new Error(`radius ${o} must be a number; got ${typeof t}.`)}}const r=o.font;if(void 0!==r){if(!isPlainObject(r))throw new Error(`A brand's font is an object of font names; got ${typeof r}.`);for(const o of Object.keys(r)){if(!isOneOf(FONT_NAMES,o))throw new Error(`unknown font ${o}; allowed: ${FONT_NAMES.join(", ")}.`);const t=r[o];if(!isPlainObject(t))throw new Error(`font ${o} must be an object of weights; got ${typeof t}.`);for(const e of Object.keys(t)){if(!isOneOf(WEIGHT_NAMES,e))throw new Error(`unknown font weight ${e} in font ${o}; allowed: ${WEIGHT_NAMES.join(", ")}.`);const n=t[e];if("string"!=typeof n||0===n.length)throw new Error(`font ${o} weight ${e} must be a non-empty string.`)}}}},validateSettings=o=>{if(void 0===o)return;if(!isPlainObject(o))throw new Error(`Theme settings is an object; got ${typeof o}.`);for(const t of Object.keys(o))if(!isOneOf(SETTINGS_KEYS,t))throw new Error(`Theme settings take ${SETTINGS_KEYS.join(", ")} only; ${t} is not allowed.`);const t=o.components;if(void 0!==t){if(!isPlainObject(t))throw new Error(`Theme settings components is an object of component names; got ${typeof t}.`);for(const o of Object.keys(t)){if(!hasKey(COMPONENT_SETTING_KEYS,o))throw new Error(`unknown component ${o} in theme settings; allowed: ${Object.keys(COMPONENT_SETTING_KEYS).join(", ")}.`);const e=t[o];if(void 0===e)continue;if(!isPlainObject(e))throw new Error(`theme settings for ${o} is an object; got ${typeof e}.`);const n=COMPONENT_SETTING_KEYS[o];for(const t of Object.keys(e))if(!(t in n))throw new Error(`unknown setting ${t} for ${o}; allowed: ${Object.keys(n).join(", ")}.`)}}},TONES=["primary","success","warning","danger","info"],setComponentSettings=(o,t,e)=>{o[t]=e},mergeComponentSettings=(o,t,e)=>({...hasKey(o,e)?o[e]:void 0,...void 0!==t&&hasKey(t,e)?t[e]:void 0});export const mergeBrand=(o,t,e)=>{validateBrand(t),validateSettings(e);const n={};for(const[e,r]of Object.entries(t?.colors?.[o.mode]??{}))void 0!==r&&(n[e]=r);const r={...o.colors,...n},colorOf=o=>{const t=r[o];if(void 0===t)throw new Error(`The theme has no colour ${o}.`);return t},i={...o.radius,...t?.radius},s={...o.font};if(void 0!==t?.font)for(const e of keysOf(t.font))s[e]={...o.font[e],...t.font[e]};const a=[colorOf("bg"),colorOf("bg-subtle"),colorOf("bg-muted")],f={};for(const t of TONES){const e="string"==typeof n[t];let r=colorOf(t);if(e||"string"==typeof n[`on-${t}`]){const o=deriveSolidFill(r,colorOf(`on-${t}`));o!==r&&(f[t]=o,r=o)}if(e&&"string"!=typeof n[`${t}-text`]&&(f[`${t}-text`]=deriveToneInk(r,a,o.mode)),"primary"===t&&(e||void 0!==f.primary)){const t=deriveStateFills(r,colorOf("on-primary"),{fill:o.colors.primary,hover:o.colors["primary-hover"],pressed:o.colors["primary-pressed"]});"string"!=typeof n["primary-hover"]&&(f["primary-hover"]=t.hover),"string"!=typeof n["primary-pressed"]&&(f["primary-pressed"]=t.pressed)}}const d=o.settings.components,l=e?.components,c={},p=new Set([...keysOf(d),...void 0===l?[]:keysOf(l)]);for(const o of p)setComponentSettings(c,o,mergeComponentSettings(d,l,o));const u=e?.maxFontSizeMultiplier??o.settings.maxFontSizeMultiplier,O={icons:{...o.settings.icons,...e?.icons},gradients:{...o.settings.gradients,...e?.gradients},textVariants:{...o.settings.textVariants,...e?.textVariants},components:c,...void 0===u?{}:{maxFontSizeMultiplier:u}},m={...o.colors,...Object.fromEntries(Object.entries(n).filter(([o])=>!isOneOf(COLOR_NAMES,o))),...Object.fromEntries(COLOR_NAMES.map(o=>[o,f[o]??colorOf(o)]))},w={...o,colors:m,radius:i,font:s,settings:O};return validateComponentTokens(w),w};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{StyleSheet}from"react-native";const edgePaddingOf=(t,e)=>{const d=StyleSheet.flatten(t),n=d?.[e]??d?.paddingVertical??d?.padding;return"number"==typeof n?n:0};export const topPaddingOf=t=>edgePaddingOf(t,"paddingTop");export const bottomPaddingOf=t=>edgePaddingOf(t,"paddingBottom");
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Draws the same Iconsax glyphs webority-ui's `AppIcon` draws on the web,
|
|
5
5
|
* keyed by the same names, so a feature that says `<AppIcon name="send" />`
|
|
6
6
|
* looks identical in the portal and in the app. Two tiers, both generated
|
|
7
|
-
* from webority-ui's icon map by `scripts/gen-icons.
|
|
7
|
+
* from webority-ui's icon map by `scripts/gen-icons.mts` (never hand-edit them):
|
|
8
8
|
*
|
|
9
9
|
* - the curated set: the design system's semantic names ("plus",
|
|
10
10
|
* "eye-off", "alert-circle") in `glyphs.g.ts` (linear, evaluated at
|
|
@@ -33,7 +33,9 @@ export declare class AuthedImageHttpError extends Error {
|
|
|
33
33
|
readonly status: number;
|
|
34
34
|
constructor(message: string, options: {
|
|
35
35
|
status: number;
|
|
36
|
-
} &
|
|
36
|
+
} & {
|
|
37
|
+
cause?: unknown;
|
|
38
|
+
});
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* The server says the image is gone or no longer this user's: a 4xx other
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* One glyph for Select, InlineSelect, PickerTrigger and PhoneNumberInput so
|
|
5
5
|
* the indicator never drifts between trigger components. It is the design
|
|
6
6
|
* system's line chevron (AppIcon `chevron-down`), reached through the icon
|
|
7
|
-
* registry so an app can swap it with `theme.settings.icons.chevronDown
|
|
8
|
-
* be a filled triangle drawn with view borders. Pass `open` to get the 180°
|
|
7
|
+
* registry so an app can swap it with `theme.settings.icons.chevronDown`. Pass `open` to get the 180°
|
|
9
8
|
* rotate-on-open animation; omit it for a static chevron.
|
|
10
9
|
*/
|
|
11
10
|
import type React from "react";
|
|
@@ -15,7 +15,7 @@ export interface CallingCode {
|
|
|
15
15
|
label: string;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* A short list of countries, sorted by name.
|
|
18
|
+
* A short list of countries, sorted by name. Not the picker's default
|
|
19
19
|
* (that is `ALL_CALLING_CODES`); pass it as `countries` to keep a short list.
|
|
20
20
|
*/
|
|
21
21
|
export declare const DEFAULT_CALLING_CODES: ReadonlyArray<CallingCode>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SkeletonClock: single shared animation tick for every <Skeleton> on screen.
|
|
3
3
|
*
|
|
4
|
-
* Why this exists:
|
|
5
|
-
* `Animated.loop`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* surface feels noisy. CSS-driven web skeleton libs (react-loading-skeleton,
|
|
4
|
+
* Why this exists: every Skeleton on screen shares one animation tick. Separate
|
|
5
|
+
* `Animated.loop`s (a list of 20 placeholders = 20 native-driver timers) start at
|
|
6
|
+
* slightly different mount frames, so their shimmer bands drift out of phase
|
|
7
|
+
* within ~1s and the surface feels noisy. CSS-driven web skeleton libs (react-loading-skeleton,
|
|
9
8
|
* MUI) avoid this because the browser owns a single timeline. We emulate
|
|
10
9
|
* that on RN by hoisting the loop into context.
|
|
11
10
|
*
|
|
@@ -24,8 +24,6 @@ export interface ToastOptions {
|
|
|
24
24
|
textStyle?: StyleProp<TextStyle> | undefined;
|
|
25
25
|
/** Style applied to the leading icon circle wrapper. */
|
|
26
26
|
iconCircleStyle?: StyleProp<ViewStyle> | undefined;
|
|
27
|
-
/** Style applied to the message Text (alias-ish of `textStyle` but kept distinct for slot symmetry). */
|
|
28
|
-
messageStyle?: StyleProp<TextStyle> | undefined;
|
|
29
27
|
/** Style applied to the trailing action Pressable. */
|
|
30
28
|
actionButtonStyle?: StyleProp<ViewStyle> | undefined;
|
|
31
29
|
testID?: string | undefined;
|
|
@@ -30,13 +30,7 @@ export interface UsePressAnimationOptions {
|
|
|
30
30
|
enabled?: boolean | undefined;
|
|
31
31
|
}
|
|
32
32
|
export interface UsePressAnimationResult {
|
|
33
|
-
|
|
34
|
-
opacity: Animated.Value;
|
|
35
|
-
translateY: Animated.Value;
|
|
36
|
-
/**
|
|
37
|
-
* The three values composed for an `Animated.View`. Callers that only ever
|
|
38
|
-
* used `scale` keep working; new callers spread this and get every preset.
|
|
39
|
-
*/
|
|
33
|
+
/** The press feedback composed for an `Animated.View`, the same for every preset. */
|
|
40
34
|
style: {
|
|
41
35
|
transform: [{
|
|
42
36
|
scale: Animated.Value;
|
|
@@ -3,6 +3,8 @@ import type { BrandOverrides, ColorMode, Theme, ThemeSettings } from "./types";
|
|
|
3
3
|
export type ColorSchemePreference = "light" | "dark" | "system";
|
|
4
4
|
export interface ThemeProviderProps {
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
/** Fixes the colour mode for the whole tree and ignores the OS scheme. Cannot be combined with `persistKey` or `initialPreference`. */
|
|
7
|
+
mode?: ColorMode | undefined;
|
|
6
8
|
/** The preference before a saved one is read (or when nothing is saved). Default `'system'`. */
|
|
7
9
|
initialPreference?: ColorSchemePreference | undefined;
|
|
8
10
|
/**
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Draws the same Iconsax glyphs webority-ui's `AppIcon` draws on the web,
|
|
5
5
|
* keyed by the same names, so a feature that says `<AppIcon name="send" />`
|
|
6
6
|
* looks identical in the portal and in the app. Two tiers, both generated
|
|
7
|
-
* from webority-ui's icon map by `scripts/gen-icons.
|
|
7
|
+
* from webority-ui's icon map by `scripts/gen-icons.mts` (never hand-edit them):
|
|
8
8
|
*
|
|
9
9
|
* - the curated set: the design system's semantic names ("plus",
|
|
10
10
|
* "eye-off", "alert-circle") in `glyphs.g.ts` (linear, evaluated at
|
|
@@ -33,7 +33,9 @@ export declare class AuthedImageHttpError extends Error {
|
|
|
33
33
|
readonly status: number;
|
|
34
34
|
constructor(message: string, options: {
|
|
35
35
|
status: number;
|
|
36
|
-
} &
|
|
36
|
+
} & {
|
|
37
|
+
cause?: unknown;
|
|
38
|
+
});
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* The server says the image is gone or no longer this user's: a 4xx other
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* One glyph for Select, InlineSelect, PickerTrigger and PhoneNumberInput so
|
|
5
5
|
* the indicator never drifts between trigger components. It is the design
|
|
6
6
|
* system's line chevron (AppIcon `chevron-down`), reached through the icon
|
|
7
|
-
* registry so an app can swap it with `theme.settings.icons.chevronDown
|
|
8
|
-
* be a filled triangle drawn with view borders. Pass `open` to get the 180°
|
|
7
|
+
* registry so an app can swap it with `theme.settings.icons.chevronDown`. Pass `open` to get the 180°
|
|
9
8
|
* rotate-on-open animation; omit it for a static chevron.
|
|
10
9
|
*/
|
|
11
10
|
import type React from "react";
|
|
@@ -15,7 +15,7 @@ export interface CallingCode {
|
|
|
15
15
|
label: string;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* A short list of countries, sorted by name.
|
|
18
|
+
* A short list of countries, sorted by name. Not the picker's default
|
|
19
19
|
* (that is `ALL_CALLING_CODES`); pass it as `countries` to keep a short list.
|
|
20
20
|
*/
|
|
21
21
|
export declare const DEFAULT_CALLING_CODES: ReadonlyArray<CallingCode>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SkeletonClock: single shared animation tick for every <Skeleton> on screen.
|
|
3
3
|
*
|
|
4
|
-
* Why this exists:
|
|
5
|
-
* `Animated.loop`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* surface feels noisy. CSS-driven web skeleton libs (react-loading-skeleton,
|
|
4
|
+
* Why this exists: every Skeleton on screen shares one animation tick. Separate
|
|
5
|
+
* `Animated.loop`s (a list of 20 placeholders = 20 native-driver timers) start at
|
|
6
|
+
* slightly different mount frames, so their shimmer bands drift out of phase
|
|
7
|
+
* within ~1s and the surface feels noisy. CSS-driven web skeleton libs (react-loading-skeleton,
|
|
9
8
|
* MUI) avoid this because the browser owns a single timeline. We emulate
|
|
10
9
|
* that on RN by hoisting the loop into context.
|
|
11
10
|
*
|
|
@@ -24,8 +24,6 @@ export interface ToastOptions {
|
|
|
24
24
|
textStyle?: StyleProp<TextStyle> | undefined;
|
|
25
25
|
/** Style applied to the leading icon circle wrapper. */
|
|
26
26
|
iconCircleStyle?: StyleProp<ViewStyle> | undefined;
|
|
27
|
-
/** Style applied to the message Text (alias-ish of `textStyle` but kept distinct for slot symmetry). */
|
|
28
|
-
messageStyle?: StyleProp<TextStyle> | undefined;
|
|
29
27
|
/** Style applied to the trailing action Pressable. */
|
|
30
28
|
actionButtonStyle?: StyleProp<ViewStyle> | undefined;
|
|
31
29
|
testID?: string | undefined;
|
|
@@ -30,13 +30,7 @@ export interface UsePressAnimationOptions {
|
|
|
30
30
|
enabled?: boolean | undefined;
|
|
31
31
|
}
|
|
32
32
|
export interface UsePressAnimationResult {
|
|
33
|
-
|
|
34
|
-
opacity: Animated.Value;
|
|
35
|
-
translateY: Animated.Value;
|
|
36
|
-
/**
|
|
37
|
-
* The three values composed for an `Animated.View`. Callers that only ever
|
|
38
|
-
* used `scale` keep working; new callers spread this and get every preset.
|
|
39
|
-
*/
|
|
33
|
+
/** The press feedback composed for an `Animated.View`, the same for every preset. */
|
|
40
34
|
style: {
|
|
41
35
|
transform: [{
|
|
42
36
|
scale: Animated.Value;
|
|
@@ -3,6 +3,8 @@ import type { BrandOverrides, ColorMode, Theme, ThemeSettings } from "./types.js
|
|
|
3
3
|
export type ColorSchemePreference = "light" | "dark" | "system";
|
|
4
4
|
export interface ThemeProviderProps {
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
/** Fixes the colour mode for the whole tree and ignores the OS scheme. Cannot be combined with `persistKey` or `initialPreference`. */
|
|
7
|
+
mode?: ColorMode | undefined;
|
|
6
8
|
/** The preference before a saved one is read (or when nothing is saved). Default `'system'`. */
|
|
7
9
|
initialPreference?: ColorSchemePreference | undefined;
|
|
8
10
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.178.0",
|
|
4
4
|
"description": "Beautiful, animated, accessible React Native components, theme and form engine for Webority projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -126,13 +126,13 @@
|
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
"dependencies": {
|
|
129
|
-
"@webority/markdown-core": "0.
|
|
129
|
+
"@webority/markdown-core": "0.178.0"
|
|
130
130
|
},
|
|
131
131
|
"peerDependencies": {
|
|
132
132
|
"@react-navigation/bottom-tabs": ">=7.0.0",
|
|
133
133
|
"@react-navigation/native": ">=7.0.0",
|
|
134
|
-
"@webority/canvas-kit": "0.
|
|
135
|
-
"@webority/mobile-core": "0.
|
|
134
|
+
"@webority/canvas-kit": "0.178.0",
|
|
135
|
+
"@webority/mobile-core": "0.178.0",
|
|
136
136
|
"expo": ">=58.0.0",
|
|
137
137
|
"expo-file-system": ">=58.0.0",
|
|
138
138
|
"expo-haptics": ">=58.0.0",
|
|
@@ -196,10 +196,10 @@
|
|
|
196
196
|
"@types/jest": "29.5.14",
|
|
197
197
|
"@types/node": "25.6.0",
|
|
198
198
|
"@types/react": "19.3.0",
|
|
199
|
-
"@webority/canvas-kit": "0.
|
|
200
|
-
"@webority/mobile-core": "0.
|
|
199
|
+
"@webority/canvas-kit": "0.178.0",
|
|
200
|
+
"@webority/mobile-core": "0.178.0",
|
|
201
201
|
"@webority/mobile-dev": "0.0.0",
|
|
202
|
-
"@webority/tokens": "0.
|
|
202
|
+
"@webority/tokens": "0.178.0",
|
|
203
203
|
"expo": "58.0.23",
|
|
204
204
|
"expo-file-system": "58.0.13",
|
|
205
205
|
"expo-haptics": "58.0.7",
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
"lint:fix": "biome lint --write ./src",
|
|
226
226
|
"test": "jest",
|
|
227
227
|
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.build.json",
|
|
228
|
-
"tokens": "node ../../scripts/ensure-tokens-built.
|
|
228
|
+
"tokens": "node ../../scripts/ensure-tokens-built.mts && node ../tokens/dist/webority.js brand --library --out ../tokens/dist --phone src/theme/tokens.generated.ts",
|
|
229
229
|
"tokens:check": "node ../tokens/dist/webority.js brand --library --out ../tokens/dist --phone src/theme/tokens.generated.ts --check"
|
|
230
230
|
}
|
|
231
231
|
}
|