@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.js CHANGED
@@ -2250,9 +2250,12 @@ var SegmentedToggle = forwardRef(
2250
2250
  const resolvedClassName = className?.trim() || void 0;
2251
2251
  const setContainerRef = useMemo(() => mergeRefs(containerRef, forwardedRef), [forwardedRef]);
2252
2252
  const progress = useRef(new Animated.Value(selectedIndex)).current;
2253
+ const [contentWidths, setContentWidths] = useState([0, 0]);
2253
2254
  const [containerWidth, setContainerWidth] = useState(0);
2254
2255
  const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
2255
- const optionWidth = fullWidth ? availableOptionWidth : OPTION_MIN_WIDTH;
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;
2256
2259
  const indicatorTranslateX = progress.interpolate({
2257
2260
  inputRange: [0, 1],
2258
2261
  outputRange: [0, optionWidth + 4]
@@ -2303,7 +2306,7 @@ var SegmentedToggle = forwardRef(
2303
2306
  ]
2304
2307
  }
2305
2308
  ) : null,
2306
- options.map(({ value: optionValue, label, icon: Icon2 }) => {
2309
+ options.map(({ value: optionValue, label, icon: Icon2 }, index) => {
2307
2310
  const selected = optionValue === selectedValue;
2308
2311
  const iconColor = selected ? colors.primary : colors.whiteAlpha20;
2309
2312
  const labelColor = selected ? colors.whiteAlpha86 : colors.whiteAlpha40;
@@ -2318,12 +2321,27 @@ var SegmentedToggle = forwardRef(
2318
2321
  accessibilityState: { selected, disabled },
2319
2322
  style: [
2320
2323
  styles7.option,
2321
- fullWidth ? styles7.optionFullWidth : { width: OPTION_MIN_WIDTH, minWidth: OPTION_MIN_WIDTH }
2324
+ fullWidth ? styles7.optionFullWidth : [styles7.optionContentWidth, optionWidth > 0 && { width: optionWidth }]
2322
2325
  ],
2323
- children: /* @__PURE__ */ jsxs(View, { style: styles7.optionContent, children: [
2324
- Icon2 ? /* @__PURE__ */ jsx(Icon2, { size: ICON_SIZE4, color: iconColor }) : null,
2325
- /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles7.label, { color: labelColor }], children: label })
2326
- ] })
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
+ )
2327
2345
  },
2328
2346
  optionValue
2329
2347
  );
@@ -2371,6 +2389,9 @@ var styles7 = StyleSheet.create({
2371
2389
  flex: 1,
2372
2390
  minWidth: 0
2373
2391
  },
2392
+ optionContentWidth: {
2393
+ minWidth: OPTION_MIN_WIDTH
2394
+ },
2374
2395
  activeIndicator: {
2375
2396
  position: "absolute",
2376
2397
  top: 4,