feat(client): add Button.Icon subcomponent

Introduce Button.Icon to enforce consistent icon styling
(size, theme-aware color) instead of hardcoding Feather
props at each call site. Update showcase and json-render
registry to use it.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-14 00:28:21 +00:00
parent d3452dd452
commit 7fc544732e
3 changed files with 21 additions and 13 deletions

View File

@@ -1,4 +1,3 @@
import Feather from "@expo/vector-icons/Feather"
import { View } from "react-native" import { View } from "react-native"
import tw from "twrnc" import tw from "twrnc"
@@ -15,22 +14,22 @@ function ButtonShowcase() {
<Button <Button
style={tw`self-start`} style={tw`self-start`}
label="Add item" label="Add item"
leadingIcon={<Feather name="plus" size={18} color="#e7e5e4" />} leadingIcon={<Button.Icon name="plus" />}
/> />
</Section> </Section>
<Section title="Trailing icon"> <Section title="Trailing icon">
<Button <Button
style={tw`self-start`} style={tw`self-start`}
label="Next" label="Next"
trailingIcon={<Feather name="arrow-right" size={18} color="#e7e5e4" />} trailingIcon={<Button.Icon name="arrow-right" />}
/> />
</Section> </Section>
<Section title="Both icons"> <Section title="Both icons">
<Button <Button
style={tw`self-start`} style={tw`self-start`}
label="Download" label="Download"
leadingIcon={<Feather name="download" size={18} color="#e7e5e4" />} leadingIcon={<Button.Icon name="download" />}
trailingIcon={<Feather name="chevron-down" size={18} color="#e7e5e4" />} trailingIcon={<Button.Icon name="chevron-down" />}
/> />
</Section> </Section>
</View> </View>

View File

@@ -1,8 +1,19 @@
import Feather from "@expo/vector-icons/Feather"
import { type PressableProps, Pressable, View } from "react-native" import { type PressableProps, Pressable, View } from "react-native"
import tw from "twrnc" import tw from "twrnc"
import { SansSerifText } from "./sans-serif-text" import { SansSerifText } from "./sans-serif-text"
type FeatherIconName = React.ComponentProps<typeof Feather>["name"]
type ButtonIconProps = {
name: FeatherIconName
}
function ButtonIcon({ name }: ButtonIconProps) {
return <Feather name={name} size={18} color={tw.color("text-stone-100 dark:text-stone-200")} />
}
type ButtonProps = Omit<PressableProps, "children"> & { type ButtonProps = Omit<PressableProps, "children"> & {
label: string label: string
leadingIcon?: React.ReactNode leadingIcon?: React.ReactNode
@@ -12,7 +23,7 @@ type ButtonProps = Omit<PressableProps, "children"> & {
export function Button({ style, label, leadingIcon, trailingIcon, ...props }: ButtonProps) { export function Button({ style, label, leadingIcon, trailingIcon, ...props }: ButtonProps) {
const hasIcons = leadingIcon != null || trailingIcon != null const hasIcons = leadingIcon != null || trailingIcon != null
const textElement = <SansSerifText style={tw`text-stone-200 font-medium`}>{label}</SansSerifText> const textElement = <SansSerifText style={tw`text-stone-100 dark:text-stone-200 font-medium`}>{label}</SansSerifText>
return ( return (
<Pressable style={[tw`rounded-full bg-teal-600 px-4 py-3 w-fit`, style]} {...props}> <Pressable style={[tw`rounded-full bg-teal-600 px-4 py-3 w-fit`, style]} {...props}>
@@ -28,3 +39,5 @@ export function Button({ style, label, leadingIcon, trailingIcon, ...props }: Bu
</Pressable> </Pressable>
) )
} }
Button.Icon = ButtonIcon

View File

@@ -1,4 +1,3 @@
import Feather from "@expo/vector-icons/Feather"
import { defineRegistry } from "@json-render/react-native" import { defineRegistry } from "@json-render/react-native"
import { View } from "react-native" import { View } from "react-native"
import tw from "twrnc" import tw from "twrnc"
@@ -11,10 +10,7 @@ import { SerifText } from "@/components/ui/serif-text"
import { catalog } from "./catalog" import { catalog } from "./catalog"
function featherIcon(name: string | null | undefined) { type ButtonIconName = React.ComponentProps<typeof Button.Icon>["name"]
if (!name) return undefined
return <Feather name={name as React.ComponentProps<typeof Feather>["name"]} size={18} color="#e7e5e4" />
}
export const { registry } = defineRegistry(catalog, { export const { registry } = defineRegistry(catalog, {
components: { components: {
@@ -22,8 +18,8 @@ export const { registry } = defineRegistry(catalog, {
Button: ({ props, emit }) => ( Button: ({ props, emit }) => (
<Button <Button
label={props.label} label={props.label}
leadingIcon={featherIcon(props.leadingIcon)} leadingIcon={props.leadingIcon ? <Button.Icon name={props.leadingIcon as ButtonIconName} /> : undefined}
trailingIcon={featherIcon(props.trailingIcon)} trailingIcon={props.trailingIcon ? <Button.Icon name={props.trailingIcon as ButtonIconName} /> : undefined}
onPress={() => emit("press")} onPress={() => emit("press")}
/> />
), ),