@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.js CHANGED
@@ -2224,7 +2224,9 @@ var styles6 = StyleSheet.create({
2224
2224
  var ICON_SIZE4 = 20;
2225
2225
  var ANIMATION_DURATION = 200;
2226
2226
  var OPTION_HORIZONTAL_PADDING = 16;
2227
+ var OPTION_CONTENT_GAP = 12;
2227
2228
  var OPTION_MIN_WIDTH = 97;
2229
+ var OPTION_MEASUREMENT_TOLERANCE = 0.5;
2228
2230
  var SegmentedToggle = forwardRef(
2229
2231
  function SegmentedToggle2({
2230
2232
  options,
@@ -2253,12 +2255,15 @@ var SegmentedToggle = forwardRef(
2253
2255
  const [contentWidths, setContentWidths] = useState([0, 0]);
2254
2256
  const [containerWidth, setContainerWidth] = useState(0);
2255
2257
  const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
2256
- const widestContentWidth = Math.max(...contentWidths);
2257
- const contentBasedOptionWidth = widestContentWidth > 0 ? Math.max(OPTION_MIN_WIDTH, widestContentWidth + OPTION_HORIZONTAL_PADDING * 2) : 0;
2258
- const optionWidth = fullWidth ? availableOptionWidth : contentBasedOptionWidth;
2258
+ const resolveContentOptionWidth = (contentWidth) => contentWidth > 0 ? Math.max(
2259
+ OPTION_MIN_WIDTH,
2260
+ contentWidth + OPTION_HORIZONTAL_PADDING * 2 + OPTION_MEASUREMENT_TOLERANCE
2261
+ ) : 0;
2262
+ const optionWidths = fullWidth ? [availableOptionWidth, availableOptionWidth] : [resolveContentOptionWidth(contentWidths[0]), resolveContentOptionWidth(contentWidths[1])];
2263
+ const selectedOptionWidth = optionWidths[selectedIndex];
2259
2264
  const indicatorTranslateX = progress.interpolate({
2260
2265
  inputRange: [0, 1],
2261
- outputRange: [0, optionWidth + 4]
2266
+ outputRange: [0, optionWidths[0] + 4]
2262
2267
  });
2263
2268
  useApplyWebClassName(containerRef, resolvedClassName);
2264
2269
  useEffect(() => {
@@ -2296,13 +2301,37 @@ var SegmentedToggle = forwardRef(
2296
2301
  ],
2297
2302
  accessibilityRole: "radiogroup",
2298
2303
  children: [
2299
- optionWidth > 0 ? /* @__PURE__ */ jsx(
2304
+ !fullWidth ? options.map(({ value: optionValue, label, icon: Icon2 }, index) => /* @__PURE__ */ jsxs(
2305
+ View,
2306
+ {
2307
+ pointerEvents: "none",
2308
+ "aria-hidden": true,
2309
+ accessibilityElementsHidden: true,
2310
+ importantForAccessibility: "no-hide-descendants",
2311
+ onLayout: (event) => {
2312
+ const nextWidth = event.nativeEvent.layout.width;
2313
+ setContentWidths((currentWidths) => {
2314
+ if (currentWidths[index] === nextWidth) return currentWidths;
2315
+ const nextWidths = [currentWidths[0], currentWidths[1]];
2316
+ nextWidths[index] = nextWidth;
2317
+ return nextWidths;
2318
+ });
2319
+ },
2320
+ style: styles7.optionMeasurement,
2321
+ children: [
2322
+ Icon2 ? /* @__PURE__ */ jsx(Icon2, { size: ICON_SIZE4 }) : null,
2323
+ /* @__PURE__ */ jsx(Text, { style: [styles7.label, styles7.contentWidthLabel], children: label })
2324
+ ]
2325
+ },
2326
+ `${optionValue}-measurement`
2327
+ )) : null,
2328
+ selectedOptionWidth > 0 ? /* @__PURE__ */ jsx(
2300
2329
  Animated.View,
2301
2330
  {
2302
2331
  pointerEvents: "none",
2303
2332
  style: [
2304
2333
  styles7.activeIndicator,
2305
- { width: optionWidth, transform: [{ translateX: indicatorTranslateX }] }
2334
+ { width: selectedOptionWidth, transform: [{ translateX: indicatorTranslateX }] }
2306
2335
  ]
2307
2336
  }
2308
2337
  ) : null,
@@ -2321,27 +2350,26 @@ var SegmentedToggle = forwardRef(
2321
2350
  accessibilityState: { selected, disabled },
2322
2351
  style: [
2323
2352
  styles7.option,
2324
- fullWidth ? styles7.optionFullWidth : [styles7.optionContentWidth, optionWidth > 0 && { width: optionWidth }]
2353
+ fullWidth ? styles7.optionFullWidth : [
2354
+ styles7.optionContentWidth,
2355
+ optionWidths[index] > 0 && { width: optionWidths[index] }
2356
+ ]
2325
2357
  ],
2326
- children: /* @__PURE__ */ jsxs(
2327
- View,
2328
- {
2329
- onLayout: (event) => {
2330
- const nextWidth = event.nativeEvent.layout.width;
2331
- setContentWidths((currentWidths) => {
2332
- if (currentWidths[index] === nextWidth) return currentWidths;
2333
- const nextWidths = [currentWidths[0], currentWidths[1]];
2334
- nextWidths[index] = nextWidth;
2335
- return nextWidths;
2336
- });
2337
- },
2338
- style: styles7.optionContent,
2339
- children: [
2340
- Icon2 ? /* @__PURE__ */ jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
2341
- /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles7.label, { color: labelColor }], children: label })
2342
- ]
2343
- }
2344
- )
2358
+ children: /* @__PURE__ */ jsxs(View, { style: styles7.optionContent, children: [
2359
+ Icon2 ? /* @__PURE__ */ jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
2360
+ /* @__PURE__ */ jsx(
2361
+ Text,
2362
+ {
2363
+ numberOfLines: fullWidth ? 1 : void 0,
2364
+ style: [
2365
+ styles7.label,
2366
+ !fullWidth && styles7.contentWidthLabel,
2367
+ { color: labelColor }
2368
+ ],
2369
+ children: label
2370
+ }
2371
+ )
2372
+ ] })
2345
2373
  },
2346
2374
  optionValue
2347
2375
  );
@@ -2383,7 +2411,14 @@ var styles7 = StyleSheet.create({
2383
2411
  maxWidth: "100%",
2384
2412
  flexDirection: "row",
2385
2413
  alignItems: "center",
2386
- gap: 12
2414
+ gap: OPTION_CONTENT_GAP
2415
+ },
2416
+ optionMeasurement: {
2417
+ position: "absolute",
2418
+ flexDirection: "row",
2419
+ alignItems: "center",
2420
+ gap: OPTION_CONTENT_GAP,
2421
+ opacity: 0
2387
2422
  },
2388
2423
  optionFullWidth: {
2389
2424
  flex: 1,
@@ -2403,6 +2438,9 @@ var styles7 = StyleSheet.create({
2403
2438
  label: {
2404
2439
  ...segmentedToggleTypography,
2405
2440
  flexShrink: 1
2441
+ },
2442
+ contentWidthLabel: {
2443
+ flexShrink: 0
2406
2444
  }
2407
2445
  });
2408
2446
  var defaultLanguageOptions = [