@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.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,
@@ -2250,12 +2252,18 @@ var SegmentedToggle = forwardRef(
2250
2252
  const resolvedClassName = className?.trim() || void 0;
2251
2253
  const setContainerRef = useMemo(() => mergeRefs(containerRef, forwardedRef), [forwardedRef]);
2252
2254
  const progress = useRef(new Animated.Value(selectedIndex)).current;
2255
+ const [contentWidths, setContentWidths] = useState([0, 0]);
2253
2256
  const [containerWidth, setContainerWidth] = useState(0);
2254
2257
  const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
2255
- const optionWidth = fullWidth ? availableOptionWidth : OPTION_MIN_WIDTH;
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];
2256
2264
  const indicatorTranslateX = progress.interpolate({
2257
2265
  inputRange: [0, 1],
2258
- outputRange: [0, optionWidth + 4]
2266
+ outputRange: [0, optionWidths[0] + 4]
2259
2267
  });
2260
2268
  useApplyWebClassName(containerRef, resolvedClassName);
2261
2269
  useEffect(() => {
@@ -2293,17 +2301,41 @@ var SegmentedToggle = forwardRef(
2293
2301
  ],
2294
2302
  accessibilityRole: "radiogroup",
2295
2303
  children: [
2296
- 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(
2297
2329
  Animated.View,
2298
2330
  {
2299
2331
  pointerEvents: "none",
2300
2332
  style: [
2301
2333
  styles7.activeIndicator,
2302
- { width: optionWidth, transform: [{ translateX: indicatorTranslateX }] }
2334
+ { width: selectedOptionWidth, transform: [{ translateX: indicatorTranslateX }] }
2303
2335
  ]
2304
2336
  }
2305
2337
  ) : null,
2306
- options.map(({ value: optionValue, label, icon: Icon2 }) => {
2338
+ options.map(({ value: optionValue, label, icon: Icon2 }, index) => {
2307
2339
  const selected = optionValue === selectedValue;
2308
2340
  const iconColor = selected ? colors.primary : colors.whiteAlpha20;
2309
2341
  const labelColor = selected ? colors.whiteAlpha86 : colors.whiteAlpha40;
@@ -2318,11 +2350,25 @@ var SegmentedToggle = forwardRef(
2318
2350
  accessibilityState: { selected, disabled },
2319
2351
  style: [
2320
2352
  styles7.option,
2321
- fullWidth ? styles7.optionFullWidth : { width: OPTION_MIN_WIDTH, minWidth: OPTION_MIN_WIDTH }
2353
+ fullWidth ? styles7.optionFullWidth : [
2354
+ styles7.optionContentWidth,
2355
+ optionWidths[index] > 0 && { width: optionWidths[index] }
2356
+ ]
2322
2357
  ],
2323
2358
  children: /* @__PURE__ */ jsxs(View, { style: styles7.optionContent, children: [
2324
2359
  Icon2 ? /* @__PURE__ */ jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
2325
- /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles7.label, { color: labelColor }], children: label })
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
+ )
2326
2372
  ] })
2327
2373
  },
2328
2374
  optionValue
@@ -2365,12 +2411,22 @@ var styles7 = StyleSheet.create({
2365
2411
  maxWidth: "100%",
2366
2412
  flexDirection: "row",
2367
2413
  alignItems: "center",
2368
- 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
2369
2422
  },
2370
2423
  optionFullWidth: {
2371
2424
  flex: 1,
2372
2425
  minWidth: 0
2373
2426
  },
2427
+ optionContentWidth: {
2428
+ minWidth: OPTION_MIN_WIDTH
2429
+ },
2374
2430
  activeIndicator: {
2375
2431
  position: "absolute",
2376
2432
  top: 4,
@@ -2382,6 +2438,9 @@ var styles7 = StyleSheet.create({
2382
2438
  label: {
2383
2439
  ...segmentedToggleTypography,
2384
2440
  flexShrink: 1
2441
+ },
2442
+ contentWidthLabel: {
2443
+ flexShrink: 0
2385
2444
  }
2386
2445
  });
2387
2446
  var defaultLanguageOptions = [