@ecohouse/ui 0.1.21 → 0.1.22

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.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Cross-platform presentation-only UI components for EcoHouse (React Native + React Native Web)",
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
+ });
@@ -0,0 +1,2 @@
1
+ export { Amenity } from "./Amenity";
2
+ export type { AmenityProps, AmenityVariant } from "./Amenity";
@@ -1,3 +1,6 @@
1
+ export { Amenity } from "./Amenity";
2
+ export type { AmenityProps, AmenityVariant } from "./Amenity";
3
+
1
4
  export { MenuItem } from "./MenuItem";
2
5
  export type { MenuItemProps } from "./MenuItem";
3
6
  export { FavoritesButton } from "./FavoritesButton";
@@ -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(12);
25
+ expect(segmentedToggleTypography.lineHeight).toBe(14);
26
26
  });
27
27
 
28
28
  it("keeps Input, Select, and Textarea field text aligned", () => {
@@ -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 100%, letter-spacing 0. */
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: 12,
46
+ lineHeight: 14,
47
47
  letterSpacing: 0,
48
48
  } as const;
49
49