@ecohouse/ui 0.1.24 → 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,
@@ -2259,12 +2261,15 @@ var SegmentedToggle = react.forwardRef(
2259
2261
  const [contentWidths, setContentWidths] = react.useState([0, 0]);
2260
2262
  const [containerWidth, setContainerWidth] = react.useState(0);
2261
2263
  const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
2262
- const widestContentWidth = Math.max(...contentWidths);
2263
- const contentBasedOptionWidth = widestContentWidth > 0 ? Math.max(OPTION_MIN_WIDTH, widestContentWidth + OPTION_HORIZONTAL_PADDING * 2) : 0;
2264
- const optionWidth = fullWidth ? availableOptionWidth : contentBasedOptionWidth;
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];
2265
2270
  const indicatorTranslateX = progress.interpolate({
2266
2271
  inputRange: [0, 1],
2267
- outputRange: [0, optionWidth + 4]
2272
+ outputRange: [0, optionWidths[0] + 4]
2268
2273
  });
2269
2274
  useApplyWebClassName(containerRef, resolvedClassName);
2270
2275
  react.useEffect(() => {
@@ -2302,13 +2307,37 @@ var SegmentedToggle = react.forwardRef(
2302
2307
  ],
2303
2308
  accessibilityRole: "radiogroup",
2304
2309
  children: [
2305
- optionWidth > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
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(
2306
2335
  reactNative.Animated.View,
2307
2336
  {
2308
2337
  pointerEvents: "none",
2309
2338
  style: [
2310
2339
  styles7.activeIndicator,
2311
- { width: optionWidth, transform: [{ translateX: indicatorTranslateX }] }
2340
+ { width: selectedOptionWidth, transform: [{ translateX: indicatorTranslateX }] }
2312
2341
  ]
2313
2342
  }
2314
2343
  ) : null,
@@ -2327,27 +2356,26 @@ var SegmentedToggle = react.forwardRef(
2327
2356
  accessibilityState: { selected, disabled },
2328
2357
  style: [
2329
2358
  styles7.option,
2330
- fullWidth ? styles7.optionFullWidth : [styles7.optionContentWidth, optionWidth > 0 && { width: optionWidth }]
2359
+ fullWidth ? styles7.optionFullWidth : [
2360
+ styles7.optionContentWidth,
2361
+ optionWidths[index] > 0 && { width: optionWidths[index] }
2362
+ ]
2331
2363
  ],
2332
- children: /* @__PURE__ */ jsxRuntime.jsxs(
2333
- reactNative.View,
2334
- {
2335
- onLayout: (event) => {
2336
- const nextWidth = event.nativeEvent.layout.width;
2337
- setContentWidths((currentWidths) => {
2338
- if (currentWidths[index] === nextWidth) return currentWidths;
2339
- const nextWidths = [currentWidths[0], currentWidths[1]];
2340
- nextWidths[index] = nextWidth;
2341
- return nextWidths;
2342
- });
2343
- },
2344
- style: styles7.optionContent,
2345
- children: [
2346
- Icon2 ? /* @__PURE__ */ jsxRuntime.jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
2347
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [styles7.label, { color: labelColor }], children: label })
2348
- ]
2349
- }
2350
- )
2364
+ children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.optionContent, children: [
2365
+ Icon2 ? /* @__PURE__ */ jsxRuntime.jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
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
+ )
2378
+ ] })
2351
2379
  },
2352
2380
  optionValue
2353
2381
  );
@@ -2389,7 +2417,14 @@ var styles7 = reactNative.StyleSheet.create({
2389
2417
  maxWidth: "100%",
2390
2418
  flexDirection: "row",
2391
2419
  alignItems: "center",
2392
- gap: 12
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
2393
2428
  },
2394
2429
  optionFullWidth: {
2395
2430
  flex: 1,
@@ -2409,6 +2444,9 @@ var styles7 = reactNative.StyleSheet.create({
2409
2444
  label: {
2410
2445
  ...segmentedToggleTypography,
2411
2446
  flexShrink: 1
2447
+ },
2448
+ contentWidthLabel: {
2449
+ flexShrink: 0
2412
2450
  }
2413
2451
  });
2414
2452
  var defaultLanguageOptions = [