@ecohouse/ui 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -2230,7 +2230,9 @@ var styles6 = reactNative.StyleSheet.create({
|
|
|
2230
2230
|
var ICON_SIZE4 = 20;
|
|
2231
2231
|
var ANIMATION_DURATION = 200;
|
|
2232
2232
|
var OPTION_HORIZONTAL_PADDING = 16;
|
|
2233
|
+
var OPTION_CONTENT_GAP = 12;
|
|
2233
2234
|
var OPTION_MIN_WIDTH = 97;
|
|
2235
|
+
var OPTION_MEASUREMENT_TOLERANCE = 0.5;
|
|
2234
2236
|
var SegmentedToggle = react.forwardRef(
|
|
2235
2237
|
function SegmentedToggle2({
|
|
2236
2238
|
options,
|
|
@@ -2256,12 +2258,18 @@ var SegmentedToggle = react.forwardRef(
|
|
|
2256
2258
|
const resolvedClassName = className?.trim() || void 0;
|
|
2257
2259
|
const setContainerRef = react.useMemo(() => mergeRefs(containerRef, forwardedRef), [forwardedRef]);
|
|
2258
2260
|
const progress = react.useRef(new reactNative.Animated.Value(selectedIndex)).current;
|
|
2261
|
+
const [contentWidths, setContentWidths] = react.useState([0, 0]);
|
|
2259
2262
|
const [containerWidth, setContainerWidth] = react.useState(0);
|
|
2260
2263
|
const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
|
|
2261
|
-
const
|
|
2264
|
+
const resolveContentOptionWidth = (contentWidth) => contentWidth > 0 ? Math.max(
|
|
2265
|
+
OPTION_MIN_WIDTH,
|
|
2266
|
+
contentWidth + OPTION_HORIZONTAL_PADDING * 2 + OPTION_MEASUREMENT_TOLERANCE
|
|
2267
|
+
) : 0;
|
|
2268
|
+
const optionWidths = fullWidth ? [availableOptionWidth, availableOptionWidth] : [resolveContentOptionWidth(contentWidths[0]), resolveContentOptionWidth(contentWidths[1])];
|
|
2269
|
+
const selectedOptionWidth = optionWidths[selectedIndex];
|
|
2262
2270
|
const indicatorTranslateX = progress.interpolate({
|
|
2263
2271
|
inputRange: [0, 1],
|
|
2264
|
-
outputRange: [0,
|
|
2272
|
+
outputRange: [0, optionWidths[0] + 4]
|
|
2265
2273
|
});
|
|
2266
2274
|
useApplyWebClassName(containerRef, resolvedClassName);
|
|
2267
2275
|
react.useEffect(() => {
|
|
@@ -2299,17 +2307,41 @@ var SegmentedToggle = react.forwardRef(
|
|
|
2299
2307
|
],
|
|
2300
2308
|
accessibilityRole: "radiogroup",
|
|
2301
2309
|
children: [
|
|
2302
|
-
|
|
2310
|
+
!fullWidth ? options.map(({ value: optionValue, label, icon: Icon2 }, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2311
|
+
reactNative.View,
|
|
2312
|
+
{
|
|
2313
|
+
pointerEvents: "none",
|
|
2314
|
+
"aria-hidden": true,
|
|
2315
|
+
accessibilityElementsHidden: true,
|
|
2316
|
+
importantForAccessibility: "no-hide-descendants",
|
|
2317
|
+
onLayout: (event) => {
|
|
2318
|
+
const nextWidth = event.nativeEvent.layout.width;
|
|
2319
|
+
setContentWidths((currentWidths) => {
|
|
2320
|
+
if (currentWidths[index] === nextWidth) return currentWidths;
|
|
2321
|
+
const nextWidths = [currentWidths[0], currentWidths[1]];
|
|
2322
|
+
nextWidths[index] = nextWidth;
|
|
2323
|
+
return nextWidths;
|
|
2324
|
+
});
|
|
2325
|
+
},
|
|
2326
|
+
style: styles7.optionMeasurement,
|
|
2327
|
+
children: [
|
|
2328
|
+
Icon2 ? /* @__PURE__ */ jsxRuntime.jsx(Icon2, { size: ICON_SIZE4 }) : null,
|
|
2329
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.label, styles7.contentWidthLabel], children: label })
|
|
2330
|
+
]
|
|
2331
|
+
},
|
|
2332
|
+
`${optionValue}-measurement`
|
|
2333
|
+
)) : null,
|
|
2334
|
+
selectedOptionWidth > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2303
2335
|
reactNative.Animated.View,
|
|
2304
2336
|
{
|
|
2305
2337
|
pointerEvents: "none",
|
|
2306
2338
|
style: [
|
|
2307
2339
|
styles7.activeIndicator,
|
|
2308
|
-
{ width:
|
|
2340
|
+
{ width: selectedOptionWidth, transform: [{ translateX: indicatorTranslateX }] }
|
|
2309
2341
|
]
|
|
2310
2342
|
}
|
|
2311
2343
|
) : null,
|
|
2312
|
-
options.map(({ value: optionValue, label, icon: Icon2 }) => {
|
|
2344
|
+
options.map(({ value: optionValue, label, icon: Icon2 }, index) => {
|
|
2313
2345
|
const selected = optionValue === selectedValue;
|
|
2314
2346
|
const iconColor = selected ? colors.primary : colors.whiteAlpha20;
|
|
2315
2347
|
const labelColor = selected ? colors.whiteAlpha86 : colors.whiteAlpha40;
|
|
@@ -2324,11 +2356,25 @@ var SegmentedToggle = react.forwardRef(
|
|
|
2324
2356
|
accessibilityState: { selected, disabled },
|
|
2325
2357
|
style: [
|
|
2326
2358
|
styles7.option,
|
|
2327
|
-
fullWidth ? styles7.optionFullWidth :
|
|
2359
|
+
fullWidth ? styles7.optionFullWidth : [
|
|
2360
|
+
styles7.optionContentWidth,
|
|
2361
|
+
optionWidths[index] > 0 && { width: optionWidths[index] }
|
|
2362
|
+
]
|
|
2328
2363
|
],
|
|
2329
2364
|
children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.optionContent, children: [
|
|
2330
2365
|
Icon2 ? /* @__PURE__ */ jsxRuntime.jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
|
|
2331
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2366
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2367
|
+
reactNative.Text,
|
|
2368
|
+
{
|
|
2369
|
+
numberOfLines: fullWidth ? 1 : void 0,
|
|
2370
|
+
style: [
|
|
2371
|
+
styles7.label,
|
|
2372
|
+
!fullWidth && styles7.contentWidthLabel,
|
|
2373
|
+
{ color: labelColor }
|
|
2374
|
+
],
|
|
2375
|
+
children: label
|
|
2376
|
+
}
|
|
2377
|
+
)
|
|
2332
2378
|
] })
|
|
2333
2379
|
},
|
|
2334
2380
|
optionValue
|
|
@@ -2371,12 +2417,22 @@ var styles7 = reactNative.StyleSheet.create({
|
|
|
2371
2417
|
maxWidth: "100%",
|
|
2372
2418
|
flexDirection: "row",
|
|
2373
2419
|
alignItems: "center",
|
|
2374
|
-
gap:
|
|
2420
|
+
gap: OPTION_CONTENT_GAP
|
|
2421
|
+
},
|
|
2422
|
+
optionMeasurement: {
|
|
2423
|
+
position: "absolute",
|
|
2424
|
+
flexDirection: "row",
|
|
2425
|
+
alignItems: "center",
|
|
2426
|
+
gap: OPTION_CONTENT_GAP,
|
|
2427
|
+
opacity: 0
|
|
2375
2428
|
},
|
|
2376
2429
|
optionFullWidth: {
|
|
2377
2430
|
flex: 1,
|
|
2378
2431
|
minWidth: 0
|
|
2379
2432
|
},
|
|
2433
|
+
optionContentWidth: {
|
|
2434
|
+
minWidth: OPTION_MIN_WIDTH
|
|
2435
|
+
},
|
|
2380
2436
|
activeIndicator: {
|
|
2381
2437
|
position: "absolute",
|
|
2382
2438
|
top: 4,
|
|
@@ -2388,6 +2444,9 @@ var styles7 = reactNative.StyleSheet.create({
|
|
|
2388
2444
|
label: {
|
|
2389
2445
|
...segmentedToggleTypography,
|
|
2390
2446
|
flexShrink: 1
|
|
2447
|
+
},
|
|
2448
|
+
contentWidthLabel: {
|
|
2449
|
+
flexShrink: 0
|
|
2391
2450
|
}
|
|
2392
2451
|
});
|
|
2393
2452
|
var defaultLanguageOptions = [
|