@ecohouse/ui 0.1.23 → 0.1.24

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
@@ -2256,9 +2256,12 @@ var SegmentedToggle = react.forwardRef(
2256
2256
  const resolvedClassName = className?.trim() || void 0;
2257
2257
  const setContainerRef = react.useMemo(() => mergeRefs(containerRef, forwardedRef), [forwardedRef]);
2258
2258
  const progress = react.useRef(new reactNative.Animated.Value(selectedIndex)).current;
2259
+ const [contentWidths, setContentWidths] = react.useState([0, 0]);
2259
2260
  const [containerWidth, setContainerWidth] = react.useState(0);
2260
2261
  const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
2261
- const optionWidth = fullWidth ? availableOptionWidth : OPTION_MIN_WIDTH;
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;
2262
2265
  const indicatorTranslateX = progress.interpolate({
2263
2266
  inputRange: [0, 1],
2264
2267
  outputRange: [0, optionWidth + 4]
@@ -2309,7 +2312,7 @@ var SegmentedToggle = react.forwardRef(
2309
2312
  ]
2310
2313
  }
2311
2314
  ) : null,
2312
- options.map(({ value: optionValue, label, icon: Icon2 }) => {
2315
+ options.map(({ value: optionValue, label, icon: Icon2 }, index) => {
2313
2316
  const selected = optionValue === selectedValue;
2314
2317
  const iconColor = selected ? colors.primary : colors.whiteAlpha20;
2315
2318
  const labelColor = selected ? colors.whiteAlpha86 : colors.whiteAlpha40;
@@ -2324,12 +2327,27 @@ var SegmentedToggle = react.forwardRef(
2324
2327
  accessibilityState: { selected, disabled },
2325
2328
  style: [
2326
2329
  styles7.option,
2327
- fullWidth ? styles7.optionFullWidth : { width: OPTION_MIN_WIDTH, minWidth: OPTION_MIN_WIDTH }
2330
+ fullWidth ? styles7.optionFullWidth : [styles7.optionContentWidth, optionWidth > 0 && { width: optionWidth }]
2328
2331
  ],
2329
- children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles7.optionContent, children: [
2330
- Icon2 ? /* @__PURE__ */ jsxRuntime.jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
2331
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [styles7.label, { color: labelColor }], children: label })
2332
- ] })
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
+ )
2333
2351
  },
2334
2352
  optionValue
2335
2353
  );
@@ -2377,6 +2395,9 @@ var styles7 = reactNative.StyleSheet.create({
2377
2395
  flex: 1,
2378
2396
  minWidth: 0
2379
2397
  },
2398
+ optionContentWidth: {
2399
+ minWidth: OPTION_MIN_WIDTH
2400
+ },
2380
2401
  activeIndicator: {
2381
2402
  position: "absolute",
2382
2403
  top: 4,