@webority/mobile-ui 0.7.2 → 0.7.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Checkbox=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_ChoiceText=require("../FieldBase/ChoiceText.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,r){if("function"==typeof WeakMap)var t=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,r){if(!r&&e&&e.__esModule)return e;var s,o,a={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return a;if(s=r?i:t){if(s.has(e))return s.get(e);s.set(e,a)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((o=(s=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(o.get||o.set)?s(a,r,o):a[r]=e[r]);return a})(e,r)}const sizeMap={sm:16,md:20,lg:24},toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},toneOnColor=(e,r)=>{switch(r){case"success":return e.colors.onSuccess;case"warning":return e.colors.onWarning;case"error":return e.colors.onError;default:return e.colors.onPrimary}},Checkbox=exports.Checkbox=(0,_react.forwardRef)((e,r)=>{const{checked:t,defaultChecked:i,onChange:s,indeterminate:o=!1,disabled:a=!1,label:n,description:l,error:c,help:d,labelLines:u,size:p="md",tone:h="primary",accessibilityLabel:x,haptic:_,style:b,boxStyle:f,indeterminateBarStyle:m,containerStyle:y,labelStyle:g,testID:j,...v}=e,[w,C]=(0,_index.useControllableState)({value:t,defaultValue:i??!1,onChange:s}),k=(0,_index2.useTheme)(),S=(0,_react.useMemo)(()=>buildStyles(k),[k]),R=k.components.checkbox?.[p]?.boxSize??sizeMap[p],T=k.colors.border.width,N=k.components.checkbox?.labelGap??10,q=toneColor(k,h),M=w||o,F=(0,_react.useRef)((0,_index2.createAnimatedValue)(M?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.spring(F,{toValue:M?1:0,damping:k.motion.spring.snappy.damping,stiffness:k.motion.spring.snappy.stiffness,mass:k.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[M,F,k.motion.spring.snappy]);const B=F.interpolate({inputRange:[0,1],outputRange:[0,1]}),W=x??(0,_FieldBase.fieldTextAsString)(n),L=a?k.colors.border.primary:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Checkbox=void 0;var _react=require("react"),_reactNative=require("react-native"),_reactNativeSvg=_interopRequireWildcard(require("react-native-svg")),_index=require("../../hooks/index.js"),_index2=require("../../theme/index.js"),_corners=require("../../utils/corners.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_ChoiceText=require("../FieldBase/ChoiceText.js"),_FieldBase=require("../FieldBase/FieldBase.js"),_jsxRuntime=require("react/jsx-runtime");function _interopRequireWildcard(e,r){if("function"==typeof WeakMap)var t=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,r){if(!r&&e&&e.__esModule)return e;var s,o,a={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return a;if(s=r?i:t){if(s.has(e))return s.get(e);s.set(e,a)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((o=(s=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(o.get||o.set)?s(a,r,o):a[r]=e[r]);return a})(e,r)}const sizeMap={sm:16,md:20,lg:24},toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},toneOnColor=(e,r)=>{switch(r){case"success":return e.colors.onSuccess;case"warning":return e.colors.onWarning;case"error":return e.colors.onError;default:return e.colors.onPrimary}},Checkbox=exports.Checkbox=(0,_react.forwardRef)((e,r)=>{const{checked:t,defaultChecked:i,onChange:s,indeterminate:o=!1,disabled:a=!1,label:n,description:l,error:c,help:d,labelLines:u,size:p="md",tone:h="primary",accessibilityLabel:x,haptic:_,style:b,boxStyle:f,indeterminateBarStyle:m,containerStyle:y,labelStyle:g,testID:j,...v}=e,[w,C]=(0,_index.useControllableState)({value:t,defaultValue:i??!1,onChange:s}),k=(0,_index2.useTheme)(),S=(0,_react.useMemo)(()=>buildStyles(k),[k]),R=k.components.checkbox?.[p]?.boxSize??sizeMap[p],T=k.colors.border.width,N=k.components.checkbox?.labelGap??10,q=toneColor(k,h),M=w||o,F=(0,_react.useRef)((0,_index2.createAnimatedValue)(M?1:0)).current;(0,_react.useEffect)(()=>{const e=_reactNative.Animated.spring(F,{toValue:M?1:0,damping:k.motion.spring.snappy.damping,stiffness:k.motion.spring.snappy.stiffness,mass:k.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[M,F,k.motion.spring.snappy]);const B=F.interpolate({inputRange:[0,1],outputRange:[0,1]}),W=x??(0,_FieldBase.fieldTextAsString)(n),L=M?q:a?k.colors.border.primary:(0,_FieldBase.hasFieldText)(c)?k.colors.field.borderError:k.colors.border.primary,P=M?q:a?k.colors.surface.disabled:"transparent",D=a&&!M?k.colors.text.disabled:toneOnColor(k,h),O=Math.round(.72*R),V=Math.round(.55*R),I=Math.max(2,Math.round(.12*R)),A=(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{ref:r,onPress:e=>{if(a)return;const r=(0,_hapticUtils.resolveHaptic)(_,"selection");r&&(0,_hapticUtils.triggerHaptic)(r),C(!w),v.onPressOut?.(e)},disabled:a,accessibilityRole:"checkbox",accessibilityLabel:W,accessibilityHint:v.accessibilityHint??(0,_FieldBase.fieldTextAsString)(l),accessibilityState:{checked:o?"mixed":w,disabled:a},testID:j,hitSlop:6,...v,style:({pressed:e})=>[S.row,(0,_ChoiceText.hasChoiceDetail)(l,c)?S.rowTop:null,(0,_FieldBase.hasFieldText)(d)?S.rowShrink:null,{opacity:a?.55:e?.85:1},y,b],children:[(0,_jsxRuntime.jsx)(_reactNative.View,{style:[S.box,{width:R,height:R,borderWidth:T,borderRadius:k.radius.xs,..._corners.smoothCorners,borderColor:L,backgroundColor:P},f],children:(0,_jsxRuntime.jsx)(_reactNative.Animated.View,{style:[S.glyphWrap,{opacity:F,transform:[{scale:B}]}],children:o?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[{width:V,height:I,borderRadius:I/2,..._corners.smoothCorners,backgroundColor:D},m]}):(0,_jsxRuntime.jsx)(_reactNativeSvg.default,{width:O,height:O,viewBox:"0 0 24 24",children:(0,_jsxRuntime.jsx)(_reactNativeSvg.Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:D,strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}),(0,_jsxRuntime.jsx)(_ChoiceText.ChoiceText,{label:n,description:l,error:c,disabled:a,labelLines:u||void 0,descriptionLines:u||void 0,style:{marginLeft:N},labelStyle:g})]});return(0,_FieldBase.hasFieldText)(d)?(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[S.helpRow,(0,_ChoiceText.hasChoiceDetail)(l,c)?S.rowTop:null],children:[A,(0,_jsxRuntime.jsx)(_reactNative.View,{style:[S.help,{marginLeft:k.spacing.xs}],children:d})]}):A});Checkbox.displayName="Checkbox";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"},rowShrink:{flexShrink:1},helpRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},box:{alignItems:"center",justifyContent:"center"},glyphWrap:{alignItems:"center",justifyContent:"center"}});var _default=exports.default=Checkbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useRadioGroup=exports.default=exports.RadioGroupContext=exports.Radio=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_ChoiceText=require("../FieldBase/ChoiceText.js"),_RadioDot=require("./RadioDot.js"),_jsxRuntime=require("react/jsx-runtime");const RadioGroupContext=exports.RadioGroupContext=(0,_react.createContext)(null),useRadioGroup=()=>(0,_react.useContext)(RadioGroupContext);exports.useRadioGroup=useRadioGroup;const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},Radio=exports.Radio=(0,_react.forwardRef)((e,t)=>{const{value:o,selected:i,onChange:r,disabled:s=!1,label:a,description:l,error:c,size:n="md",tone:d="primary",accessibilityLabel:u,haptic:p,style:x,containerStyle:_,circleStyle:b,dotStyle:h,labelStyle:R,testID:y,...m}=e,C=(0,_index.useTheme)(),w=(0,_react.useMemo)(()=>buildStyles(C),[C]),f=useRadioGroup();__DEV__&&void 0===o&&console.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const j=f?f.selectedValue===o:!!i,S=f&&f.disabled||s,v=toneColor(C,d),g=C.components.radio?.labelGap??10,G=u??a;return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{ref:t,onPress:e=>{if(S)return;const t=(0,_hapticUtils.resolveHaptic)(p,"selection");t&&(0,_hapticUtils.triggerHaptic)(t),f?f.onChange(o):r?.(o)},disabled:S,accessibilityRole:"radio",accessibilityLabel:G,accessibilityHint:m.accessibilityHint??l,accessibilityState:{checked:j,disabled:S},testID:y,hitSlop:6,...m,style:({pressed:e})=>[w.row,(0,_ChoiceText.hasChoiceDetail)(l,c)?w.rowTop:null,{opacity:S?.55:e?.85:1},x,_],children:[(0,_jsxRuntime.jsx)(_RadioDot.RadioDot,{selected:j,color:v,disabled:S,size:n,style:[!c||j||S?null:{borderColor:C.colors.field.borderError},b],dotStyle:h}),(0,_jsxRuntime.jsx)(_ChoiceText.ChoiceText,{label:a,description:l,error:c,disabled:S,labelLines:2,style:{marginLeft:g},labelStyle:R})]})});Radio.displayName="Radio";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});var _default=exports.default=Radio;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useRadioGroup=exports.default=exports.RadioGroupContext=exports.Radio=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../../theme/index.js"),_hapticUtils=require("../../utils/hapticUtils.js"),_ChoiceText=require("../FieldBase/ChoiceText.js"),_RadioDot=require("./RadioDot.js"),_jsxRuntime=require("react/jsx-runtime");const RadioGroupContext=exports.RadioGroupContext=(0,_react.createContext)(null),useRadioGroup=()=>(0,_react.useContext)(RadioGroupContext);exports.useRadioGroup=useRadioGroup;const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},Radio=exports.Radio=(0,_react.forwardRef)((e,t)=>{const{value:o,selected:i,onChange:r,disabled:s=!1,label:a,description:l,error:c,size:n="md",tone:d="primary",accessibilityLabel:u,haptic:p,style:x,containerStyle:_,circleStyle:b,dotStyle:h,labelStyle:R,testID:y,...m}=e,C=(0,_index.useTheme)(),w=(0,_react.useMemo)(()=>buildStyles(C),[C]),f=useRadioGroup();__DEV__&&void 0===o&&console.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const j=f?f.selectedValue===o:!!i,S=f&&f.disabled||s,v=toneColor(C,d),g=C.components.radio?.labelGap??10,G=u??a;return(0,_jsxRuntime.jsxs)(_reactNative.Pressable,{ref:t,onPress:e=>{if(S)return;const t=(0,_hapticUtils.resolveHaptic)(p,"selection");t&&(0,_hapticUtils.triggerHaptic)(t),f?f.onChange(o):r?.(o)},disabled:S,accessibilityRole:"radio",accessibilityLabel:G,accessibilityHint:m.accessibilityHint??l,accessibilityState:{checked:j,disabled:S},testID:y,hitSlop:6,...m,style:({pressed:e})=>[w.row,(0,_ChoiceText.hasChoiceDetail)(l,c)?w.rowTop:null,{opacity:S?.55:e?.85:1},x,_],children:[(0,_jsxRuntime.jsx)(_RadioDot.RadioDot,{selected:j,color:v,disabled:S&&!j,size:n,style:[!c||j||S?null:{borderColor:C.colors.field.borderError},b],dotStyle:h}),(0,_jsxRuntime.jsx)(_ChoiceText.ChoiceText,{label:a,description:l,error:c,disabled:S,labelLines:2,style:{marginLeft:g},labelStyle:R})]})});Radio.displayName="Radio";const buildStyles=e=>_reactNative.StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});var _default=exports.default=Radio;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const sizeMap={sm:16,md:20,lg:24},toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},toneOnColor=(e,r)=>{switch(r){case"success":return e.colors.onSuccess;case"warning":return e.colors.onWarning;case"error":return e.colors.onError;default:return e.colors.onPrimary}},Checkbox=forwardRef((e,r)=>{const{checked:t,defaultChecked:s,onChange:o,indeterminate:i=!1,disabled:n=!1,label:a,description:l,error:c,help:d,labelLines:h,size:p="md",tone:m="primary",accessibilityLabel:u,haptic:x,style:b,boxStyle:f,indeterminateBarStyle:g,containerStyle:y,labelStyle:w,testID:C,...S}=e,[j,k]=useControllableState({value:t,defaultValue:s??!1,onChange:o}),T=useTheme(),v=useMemo(()=>buildStyles(T),[T]),R=T.components.checkbox?.[p]?.boxSize??sizeMap[p],_=T.colors.border.width,L=T.components.checkbox?.labelGap??10,V=toneColor(T,m),M=j||i,A=useRef(createAnimatedValue(M?1:0)).current;useEffect(()=>{const e=Animated.spring(A,{toValue:M?1:0,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[M,A,T.motion.spring.snappy]);const D=A.interpolate({inputRange:[0,1],outputRange:[0,1]}),F=u??fieldTextAsString(a),I=n?T.colors.border.primary:
|
|
1
|
+
"use strict";import{forwardRef,useEffect,useMemo,useRef}from"react";import{Animated,Pressable,StyleSheet,View}from"react-native";import Svg,{Path}from"react-native-svg";import{useControllableState}from"../../hooks/index.js";import{createAnimatedValue,useTheme}from"../../theme/index.js";import{smoothCorners}from"../../utils/corners.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{fieldTextAsString,hasFieldText}from"../FieldBase/FieldBase.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";const sizeMap={sm:16,md:20,lg:24},toneColor=(e,r)=>{switch(r){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},toneOnColor=(e,r)=>{switch(r){case"success":return e.colors.onSuccess;case"warning":return e.colors.onWarning;case"error":return e.colors.onError;default:return e.colors.onPrimary}},Checkbox=forwardRef((e,r)=>{const{checked:t,defaultChecked:s,onChange:o,indeterminate:i=!1,disabled:n=!1,label:a,description:l,error:c,help:d,labelLines:h,size:p="md",tone:m="primary",accessibilityLabel:u,haptic:x,style:b,boxStyle:f,indeterminateBarStyle:g,containerStyle:y,labelStyle:w,testID:C,...S}=e,[j,k]=useControllableState({value:t,defaultValue:s??!1,onChange:o}),T=useTheme(),v=useMemo(()=>buildStyles(T),[T]),R=T.components.checkbox?.[p]?.boxSize??sizeMap[p],_=T.colors.border.width,L=T.components.checkbox?.labelGap??10,V=toneColor(T,m),M=j||i,A=useRef(createAnimatedValue(M?1:0)).current;useEffect(()=>{const e=Animated.spring(A,{toValue:M?1:0,damping:T.motion.spring.snappy.damping,stiffness:T.motion.spring.snappy.stiffness,mass:T.motion.spring.snappy.mass,useNativeDriver:!0});return e.start(),()=>e.stop()},[M,A,T.motion.spring.snappy]);const D=A.interpolate({inputRange:[0,1],outputRange:[0,1]}),F=u??fieldTextAsString(a),I=M?V:n?T.colors.border.primary:hasFieldText(c)?T.colors.field.borderError:T.colors.border.primary,P=M?V:n?T.colors.surface.disabled:"transparent",H=n&&!M?T.colors.text.disabled:toneOnColor(T,m),B=Math.round(.72*R),W=Math.round(.55*R),z=Math.max(2,Math.round(.12*R)),E=_jsxs(Pressable,{ref:r,onPress:e=>{if(n)return;const r=resolveHaptic(x,"selection");r&&triggerHaptic(r),k(!j),S.onPressOut?.(e)},disabled:n,accessibilityRole:"checkbox",accessibilityLabel:F,accessibilityHint:S.accessibilityHint??fieldTextAsString(l),accessibilityState:{checked:i?"mixed":j,disabled:n},testID:C,hitSlop:6,...S,style:({pressed:e})=>[v.row,hasChoiceDetail(l,c)?v.rowTop:null,hasFieldText(d)?v.rowShrink:null,{opacity:n?.55:e?.85:1},y,b],children:[_jsx(View,{style:[v.box,{width:R,height:R,borderWidth:_,borderRadius:T.radius.xs,...smoothCorners,borderColor:I,backgroundColor:P},f],children:_jsx(Animated.View,{style:[v.glyphWrap,{opacity:A,transform:[{scale:D}]}],children:i?_jsx(View,{style:[{width:W,height:z,borderRadius:z/2,...smoothCorners,backgroundColor:H},g]}):_jsx(Svg,{width:B,height:B,viewBox:"0 0 24 24",children:_jsx(Path,{d:"M5 12.5l4.5 4.5L19 7.5",stroke:H,strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}),_jsx(ChoiceText,{label:a,description:l,error:c,disabled:n,labelLines:h||void 0,descriptionLines:h||void 0,style:{marginLeft:L},labelStyle:w})]});return hasFieldText(d)?_jsxs(View,{style:[v.helpRow,hasChoiceDetail(l,c)?v.rowTop:null],children:[E,_jsx(View,{style:[v.help,{marginLeft:T.spacing.xs}],children:d})]}):E});Checkbox.displayName="Checkbox";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"},rowShrink:{flexShrink:1},helpRow:{flexDirection:"row",alignItems:"center"},help:{flexShrink:0},box:{alignItems:"center",justifyContent:"center"},glyphWrap:{alignItems:"center",justifyContent:"center"}});export{Checkbox};export default Checkbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{createContext,forwardRef,useContext,useMemo}from"react";import{Pressable,StyleSheet}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"./RadioDot.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const RadioGroupContext=createContext(null);export const useRadioGroup=()=>useContext(RadioGroupContext);const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},Radio=forwardRef((e,t)=>{const{value:o,selected:r,onChange:s,disabled:i=!1,label:a,description:l,error:c,size:n="md",tone:d="primary",accessibilityLabel:p,haptic:u,style:m,containerStyle:b,circleStyle:h,dotStyle:y,labelStyle:x,testID:f,...C}=e,R=useTheme(),w=useMemo(()=>buildStyles(R),[R]),S=useRadioGroup();__DEV__&&void 0===o&&console.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const g=S?S.selectedValue===o:!!r,j=S&&S.disabled||i,D=toneColor(R,d),_=R.components.radio?.labelGap??10;return _jsxs(Pressable,{ref:t,onPress:e=>{if(j)return;const t=resolveHaptic(u,"selection");t&&triggerHaptic(t),S?S.onChange(o):s?.(o)},disabled:j,accessibilityRole:"radio",accessibilityLabel:p??a,accessibilityHint:C.accessibilityHint??l,accessibilityState:{checked:g,disabled:j},testID:f,hitSlop:6,...C,style:({pressed:e})=>[w.row,hasChoiceDetail(l,c)?w.rowTop:null,{opacity:j?.55:e?.85:1},m,b],children:[_jsx(RadioDot,{selected:g,color:D,disabled:j,size:n,style:[!c||g||j?null:{borderColor:R.colors.field.borderError},h],dotStyle:y}),_jsx(ChoiceText,{label:a,description:l,error:c,disabled:j,labelLines:2,style:{marginLeft:_},labelStyle:x})]})});Radio.displayName="Radio";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});export{Radio};export default Radio;
|
|
1
|
+
"use strict";import{createContext,forwardRef,useContext,useMemo}from"react";import{Pressable,StyleSheet}from"react-native";import{useTheme}from"../../theme/index.js";import{resolveHaptic,triggerHaptic}from"../../utils/hapticUtils.js";import{ChoiceText,hasChoiceDetail}from"../FieldBase/ChoiceText.js";import{RadioDot}from"./RadioDot.js";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";export const RadioGroupContext=createContext(null);export const useRadioGroup=()=>useContext(RadioGroupContext);const toneColor=(e,t)=>{switch(t){case"success":return e.colors.success;case"warning":return e.colors.warning;case"error":return e.colors.error;default:return e.colors.primary}},Radio=forwardRef((e,t)=>{const{value:o,selected:r,onChange:s,disabled:i=!1,label:a,description:l,error:c,size:n="md",tone:d="primary",accessibilityLabel:p,haptic:u,style:m,containerStyle:b,circleStyle:h,dotStyle:y,labelStyle:x,testID:f,...C}=e,R=useTheme(),w=useMemo(()=>buildStyles(R),[R]),S=useRadioGroup();__DEV__&&void 0===o&&console.warn("[@webority/mobile-ui] Radio was rendered without a `value`. Selection compares against it, so the group cannot track which option is chosen.");const g=S?S.selectedValue===o:!!r,j=S&&S.disabled||i,D=toneColor(R,d),_=R.components.radio?.labelGap??10;return _jsxs(Pressable,{ref:t,onPress:e=>{if(j)return;const t=resolveHaptic(u,"selection");t&&triggerHaptic(t),S?S.onChange(o):s?.(o)},disabled:j,accessibilityRole:"radio",accessibilityLabel:p??a,accessibilityHint:C.accessibilityHint??l,accessibilityState:{checked:g,disabled:j},testID:f,hitSlop:6,...C,style:({pressed:e})=>[w.row,hasChoiceDetail(l,c)?w.rowTop:null,{opacity:j?.55:e?.85:1},m,b],children:[_jsx(RadioDot,{selected:g,color:D,disabled:j&&!g,size:n,style:[!c||g||j?null:{borderColor:R.colors.field.borderError},h],dotStyle:y}),_jsx(ChoiceText,{label:a,description:l,error:c,disabled:j,labelLines:2,style:{marginLeft:_},labelStyle:x})]})});Radio.displayName="Radio";const buildStyles=e=>StyleSheet.create({row:{flexDirection:"row",alignItems:"center"},rowTop:{alignItems:"flex-start"}});export{Radio};export default Radio;
|