@ecohouse/ui 0.1.21 → 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/dist/index.cjs +314 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -14
- package/dist/index.d.ts +29 -14
- package/dist/index.js +316 -201
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/SegmentedToggle/SegmentedToggle.tsx +7 -19
- package/src/index.ts +3 -0
- package/src/primitives/Amenity/Amenity.stories.tsx +64 -0
- package/src/primitives/Amenity/Amenity.tsx +178 -0
- package/src/primitives/Amenity/index.ts +2 -0
- package/src/primitives/index.ts +3 -0
- package/src/theme/colors.test.ts +1 -1
- package/src/theme/typography.ts +2 -2
package/package.json
CHANGED
|
@@ -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
|
|
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 }
|
|
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
|
|
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}
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type {
|
|
|
54
54
|
} from "./components";
|
|
55
55
|
|
|
56
56
|
export {
|
|
57
|
+
Amenity,
|
|
57
58
|
BrandLogo,
|
|
58
59
|
BRAND_LOGO_COLORS,
|
|
59
60
|
BRAND_LOGO_DEFAULT_HEIGHT,
|
|
@@ -62,6 +63,8 @@ export {
|
|
|
62
63
|
MenuItem,
|
|
63
64
|
} from "./primitives";
|
|
64
65
|
export type {
|
|
66
|
+
AmenityProps,
|
|
67
|
+
AmenityVariant,
|
|
65
68
|
BrandLogoProps,
|
|
66
69
|
BrandLogoVariant,
|
|
67
70
|
FavoritesButtonProps,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import { Amenity } from "./Amenity";
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
title: "Primitives/Amenity",
|
|
8
|
+
component: Amenity,
|
|
9
|
+
args: {
|
|
10
|
+
icon: "kitchen",
|
|
11
|
+
label: "Kitchen",
|
|
12
|
+
variant: "display",
|
|
13
|
+
},
|
|
14
|
+
argTypes: {
|
|
15
|
+
icon: {
|
|
16
|
+
control: "select",
|
|
17
|
+
options: ["kitchen", "wifi", "tv", "washer", "ac", "bbq", "forestView", "pets"],
|
|
18
|
+
},
|
|
19
|
+
variant: { control: "select", options: ["display", "selectable"] },
|
|
20
|
+
},
|
|
21
|
+
parameters: { backgrounds: { default: "black" } },
|
|
22
|
+
} satisfies Meta<typeof Amenity>;
|
|
23
|
+
|
|
24
|
+
export default meta;
|
|
25
|
+
type Story = StoryObj<typeof meta>;
|
|
26
|
+
|
|
27
|
+
export const Display: Story = {};
|
|
28
|
+
|
|
29
|
+
export const Selected: Story = {
|
|
30
|
+
args: { selected: true, variant: "selectable" },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function ControlledAmenity() {
|
|
34
|
+
const [selected, setSelected] = useState(false);
|
|
35
|
+
return (
|
|
36
|
+
<Amenity
|
|
37
|
+
icon="wifi"
|
|
38
|
+
label="Wi-Fi"
|
|
39
|
+
onSelectedChange={setSelected}
|
|
40
|
+
selected={selected}
|
|
41
|
+
variant="selectable"
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const Controlled: Story = {
|
|
47
|
+
render: () => <ControlledAmenity />,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const AllIcons: Story = {
|
|
51
|
+
render: () => (
|
|
52
|
+
<View style={styles.row}>
|
|
53
|
+
{(["kitchen", "wifi", "tv", "washer", "ac", "bbq", "forestView", "pets"] as const).map(
|
|
54
|
+
(icon) => (
|
|
55
|
+
<Amenity key={icon} icon={icon} label={icon} />
|
|
56
|
+
),
|
|
57
|
+
)}
|
|
58
|
+
</View>
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const styles = StyleSheet.create({
|
|
63
|
+
row: { flexDirection: "row", flexWrap: "wrap", gap: 16 },
|
|
64
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { forwardRef, useMemo, useRef, useState, type ComponentRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Platform,
|
|
4
|
+
Pressable,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Text,
|
|
7
|
+
View,
|
|
8
|
+
type PressableProps,
|
|
9
|
+
type StyleProp,
|
|
10
|
+
type TextStyle,
|
|
11
|
+
type ViewStyle,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
import { AmenityIcon, type AmenityName } from "../../icons/Amenity";
|
|
14
|
+
import { colors, fonts } from "../../theme";
|
|
15
|
+
import { mergeRefs } from "../../utils/mergeRefs";
|
|
16
|
+
import { useApplyWebClassName } from "../../utils/useApplyWebClassName";
|
|
17
|
+
|
|
18
|
+
export type AmenityVariant = "display" | "selectable";
|
|
19
|
+
|
|
20
|
+
export interface AmenityProps extends Omit<
|
|
21
|
+
PressableProps,
|
|
22
|
+
"children" | "disabled" | "onPress" | "style"
|
|
23
|
+
> {
|
|
24
|
+
icon: AmenityName;
|
|
25
|
+
label: string;
|
|
26
|
+
variant?: AmenityVariant;
|
|
27
|
+
selected?: boolean;
|
|
28
|
+
defaultSelected?: boolean;
|
|
29
|
+
onSelectedChange?: (selected: boolean) => void;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
style?: StyleProp<ViewStyle>;
|
|
32
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const Amenity = forwardRef<ComponentRef<typeof View>, AmenityProps>(function Amenity(
|
|
37
|
+
{
|
|
38
|
+
icon,
|
|
39
|
+
label,
|
|
40
|
+
variant = "display",
|
|
41
|
+
selected,
|
|
42
|
+
defaultSelected = false,
|
|
43
|
+
onSelectedChange,
|
|
44
|
+
disabled = false,
|
|
45
|
+
style,
|
|
46
|
+
labelStyle,
|
|
47
|
+
className,
|
|
48
|
+
accessibilityLabel,
|
|
49
|
+
...rest
|
|
50
|
+
},
|
|
51
|
+
forwardedRef,
|
|
52
|
+
) {
|
|
53
|
+
const rootRef = useRef<ComponentRef<typeof View>>(null);
|
|
54
|
+
const setRootRef = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);
|
|
55
|
+
const isControlled = typeof selected === "boolean";
|
|
56
|
+
const [uncontrolledSelected, setUncontrolledSelected] = useState(defaultSelected);
|
|
57
|
+
const isSelected = isControlled ? selected : uncontrolledSelected;
|
|
58
|
+
const isSelectable = variant === "selectable";
|
|
59
|
+
const iconColor = isSelectable && isSelected ? colors.primary : colors.white;
|
|
60
|
+
|
|
61
|
+
useApplyWebClassName(rootRef, className?.trim() || undefined);
|
|
62
|
+
|
|
63
|
+
const content = (
|
|
64
|
+
<>
|
|
65
|
+
<View style={styles.iconSlot}>
|
|
66
|
+
<AmenityIcon color={iconColor} name={icon} />
|
|
67
|
+
</View>
|
|
68
|
+
<Text
|
|
69
|
+
style={[
|
|
70
|
+
styles.label,
|
|
71
|
+
isSelectable ? styles.selectableLabel : styles.displayLabel,
|
|
72
|
+
Platform.OS === "android" ? styles.labelAndroid : null,
|
|
73
|
+
labelStyle,
|
|
74
|
+
]}
|
|
75
|
+
>
|
|
76
|
+
{label}
|
|
77
|
+
</Text>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
if (!isSelectable) {
|
|
82
|
+
return (
|
|
83
|
+
<View
|
|
84
|
+
{...rest}
|
|
85
|
+
ref={setRootRef}
|
|
86
|
+
accessibilityLabel={accessibilityLabel ?? label}
|
|
87
|
+
accessibilityRole="text"
|
|
88
|
+
style={[styles.base, styles.display, style]}
|
|
89
|
+
>
|
|
90
|
+
{content}
|
|
91
|
+
</View>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const handlePress = () => {
|
|
96
|
+
if (disabled) return;
|
|
97
|
+
const nextSelected = !isSelected;
|
|
98
|
+
if (!isControlled) setUncontrolledSelected(nextSelected);
|
|
99
|
+
onSelectedChange?.(nextSelected);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<Pressable
|
|
104
|
+
{...rest}
|
|
105
|
+
ref={setRootRef}
|
|
106
|
+
accessibilityLabel={accessibilityLabel ?? label}
|
|
107
|
+
accessibilityRole="checkbox"
|
|
108
|
+
accessibilityState={{ checked: isSelected, disabled }}
|
|
109
|
+
disabled={disabled}
|
|
110
|
+
onPress={handlePress}
|
|
111
|
+
style={[
|
|
112
|
+
styles.base,
|
|
113
|
+
styles.selectable,
|
|
114
|
+
isSelected && styles.selected,
|
|
115
|
+
disabled && styles.disabled,
|
|
116
|
+
style,
|
|
117
|
+
]}
|
|
118
|
+
>
|
|
119
|
+
{content}
|
|
120
|
+
</Pressable>
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const styles = StyleSheet.create({
|
|
125
|
+
base: {
|
|
126
|
+
height: 44,
|
|
127
|
+
paddingVertical: 12,
|
|
128
|
+
paddingHorizontal: 16,
|
|
129
|
+
flexDirection: "row",
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
alignSelf: "flex-start",
|
|
132
|
+
backgroundColor: colors.grey700,
|
|
133
|
+
},
|
|
134
|
+
display: {
|
|
135
|
+
gap: 8,
|
|
136
|
+
borderRadius: 39,
|
|
137
|
+
backgroundColor: colors.grey750,
|
|
138
|
+
},
|
|
139
|
+
selectable: {
|
|
140
|
+
gap: 12,
|
|
141
|
+
borderWidth: 1,
|
|
142
|
+
borderColor: "transparent",
|
|
143
|
+
borderStyle: "solid",
|
|
144
|
+
borderRadius: 79,
|
|
145
|
+
},
|
|
146
|
+
selected: {
|
|
147
|
+
borderColor: colors.primary,
|
|
148
|
+
},
|
|
149
|
+
disabled: {
|
|
150
|
+
opacity: 0.6,
|
|
151
|
+
},
|
|
152
|
+
iconSlot: {
|
|
153
|
+
width: 20,
|
|
154
|
+
height: 20,
|
|
155
|
+
alignItems: "center",
|
|
156
|
+
justifyContent: "center",
|
|
157
|
+
flexShrink: 0,
|
|
158
|
+
},
|
|
159
|
+
label: {
|
|
160
|
+
fontFamily: fonts.sans,
|
|
161
|
+
color: colors.white,
|
|
162
|
+
},
|
|
163
|
+
displayLabel: {
|
|
164
|
+
fontSize: 14,
|
|
165
|
+
fontWeight: "500",
|
|
166
|
+
lineHeight: 14,
|
|
167
|
+
letterSpacing: 0,
|
|
168
|
+
},
|
|
169
|
+
selectableLabel: {
|
|
170
|
+
fontSize: 12,
|
|
171
|
+
fontWeight: "700",
|
|
172
|
+
lineHeight: 13.44,
|
|
173
|
+
letterSpacing: 0,
|
|
174
|
+
},
|
|
175
|
+
labelAndroid: {
|
|
176
|
+
includeFontPadding: false,
|
|
177
|
+
},
|
|
178
|
+
});
|
package/src/primitives/index.ts
CHANGED
package/src/theme/colors.test.ts
CHANGED
|
@@ -22,7 +22,7 @@ describe("design tokens", () => {
|
|
|
22
22
|
expect(buttonTypography.lg.fontSize).toBe(14);
|
|
23
23
|
expect(buttonTypography.lg.fontWeight).toBe("600");
|
|
24
24
|
expect(segmentedToggleTypography.fontSize).toBe(12);
|
|
25
|
-
expect(segmentedToggleTypography.lineHeight).toBe(
|
|
25
|
+
expect(segmentedToggleTypography.lineHeight).toBe(14);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it("keeps Input, Select, and Textarea field text aligned", () => {
|
package/src/theme/typography.ts
CHANGED
|
@@ -38,12 +38,12 @@ export const statCardTypography = {
|
|
|
38
38
|
letterSpacing: 0,
|
|
39
39
|
} as const;
|
|
40
40
|
|
|
41
|
-
/** Segmented toggle label — Medium 12, line-height
|
|
41
|
+
/** Segmented toggle label — Medium 12, 14px line-height, letter-spacing 0. */
|
|
42
42
|
export const segmentedToggleTypography = {
|
|
43
43
|
fontFamily: fonts.sans,
|
|
44
44
|
fontSize: 12,
|
|
45
45
|
fontWeight: "500" as const,
|
|
46
|
-
lineHeight:
|
|
46
|
+
lineHeight: 14,
|
|
47
47
|
letterSpacing: 0,
|
|
48
48
|
} as const;
|
|
49
49
|
|