@ecohouse/ui 0.1.22 → 0.1.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecohouse/ui",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Cross-platform presentation-only UI components for EcoHouse (React Native + React Native Web)",
@@ -37,6 +37,7 @@ export interface SegmentedToggleProps extends Omit<ViewProps, "style" | "childre
37
37
  const ICON_SIZE = 20;
38
38
  const ANIMATION_DURATION = 200;
39
39
  const OPTION_HORIZONTAL_PADDING = 16;
40
+ const OPTION_MIN_WIDTH = 97;
40
41
 
41
42
  export const SegmentedToggle = forwardRef<ComponentRef<typeof View>, SegmentedToggleProps>(
42
43
  function SegmentedToggle(
@@ -66,13 +67,9 @@ export const SegmentedToggle = forwardRef<ComponentRef<typeof View>, SegmentedTo
66
67
  const resolvedClassName = className?.trim() || undefined;
67
68
  const setContainerRef = useMemo(() => mergeRefs(containerRef, forwardedRef), [forwardedRef]);
68
69
  const progress = useRef(new Animated.Value(selectedIndex)).current;
69
- const [contentWidths, setContentWidths] = useState<[number, number]>([0, 0]);
70
70
  const [containerWidth, setContainerWidth] = useState(0);
71
71
  const availableOptionWidth = Math.max(0, (containerWidth - 12) / 2);
72
- const widestContentWidth = Math.max(...contentWidths);
73
- const contentBasedOptionWidth =
74
- widestContentWidth > 0 ? widestContentWidth + OPTION_HORIZONTAL_PADDING * 2 : 0;
75
- const optionWidth = fullWidth ? availableOptionWidth : contentBasedOptionWidth;
72
+ const optionWidth = fullWidth ? availableOptionWidth : OPTION_MIN_WIDTH;
76
73
  const indicatorTranslateX = progress.interpolate({
77
74
  inputRange: [0, 1],
78
75
  outputRange: [0, optionWidth + 4],
@@ -126,7 +123,7 @@ export const SegmentedToggle = forwardRef<ComponentRef<typeof View>, SegmentedTo
126
123
  ]}
127
124
  />
128
125
  ) : null}
129
- {options.map(({ value: optionValue, label, icon: Icon }, index) => {
126
+ {options.map(({ value: optionValue, label, icon: Icon }) => {
130
127
  const selected = optionValue === selectedValue;
131
128
  const iconColor = selected ? colors.primary : colors.whiteAlpha20;
132
129
  const labelColor = selected ? colors.whiteAlpha86 : colors.whiteAlpha40;
@@ -142,21 +139,12 @@ export const SegmentedToggle = forwardRef<ComponentRef<typeof View>, SegmentedTo
142
139
  accessibilityState={{ selected, disabled }}
143
140
  style={[
144
141
  styles.option,
145
- fullWidth ? styles.optionFullWidth : optionWidth > 0 && { minWidth: optionWidth },
142
+ fullWidth
143
+ ? styles.optionFullWidth
144
+ : { width: OPTION_MIN_WIDTH, minWidth: OPTION_MIN_WIDTH },
146
145
  ]}
147
146
  >
148
- <View
149
- onLayout={(event) => {
150
- const nextWidth = event.nativeEvent.layout.width;
151
- setContentWidths((currentWidths) => {
152
- if (currentWidths[index] === nextWidth) return currentWidths;
153
- const nextWidths: [number, number] = [currentWidths[0], currentWidths[1]];
154
- nextWidths[index] = nextWidth;
155
- return nextWidths;
156
- });
157
- }}
158
- style={styles.optionContent}
159
- >
147
+ <View style={styles.optionContent}>
160
148
  {Icon ? <Icon size={ICON_SIZE} color={iconColor} /> : null}
161
149
  <Text numberOfLines={1} style={[styles.label, { color: labelColor }]}>
162
150
  {label}