|
| 1 | +import { RuneChildren, RuneElement, RuneView } from "@rune-ui/types"; |
| 2 | +import { createHtml } from "@rune-ui/jsx"; |
| 3 | +import { View } from "rune-ts"; |
| 4 | +import { buttonParts } from "./button.anatomy"; |
| 5 | + |
| 6 | +// Button 컴포넌트의 루트 |
| 7 | +export interface RuneUIButtonRootProps extends RuneElement<"button"> { |
| 8 | + children?: RuneChildren; |
| 9 | +} |
| 10 | + |
| 11 | +export class ButtonRoot extends View<RuneUIButtonRootProps> { |
| 12 | + override template() { |
| 13 | + const { children, ...rest } = this.data; |
| 14 | + return ( |
| 15 | + <button {...rest} {...buttonParts.root.attrs}> |
| 16 | + {children} |
| 17 | + </button> |
| 18 | + ); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +// Button 컴포넌트의 내부 |
| 23 | +export interface RuneUIButtonInnerProps extends RuneElement<"span"> { |
| 24 | + children?: RuneChildren; |
| 25 | +} |
| 26 | + |
| 27 | +export class ButtonInner extends View<RuneUIButtonInnerProps> { |
| 28 | + override template() { |
| 29 | + const { children, ...rest } = this.data; |
| 30 | + |
| 31 | + return ( |
| 32 | + <span {...rest} {...buttonParts.inner.attrs}> |
| 33 | + {children} |
| 34 | + </span> |
| 35 | + ); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// Button 컴포넌트의 왼쪽 아이콘 |
| 40 | +export interface RuneUIButtonLeftIconProps extends RuneElement<"span"> { |
| 41 | + icon: RuneView; |
| 42 | +} |
| 43 | + |
| 44 | +export class ButtonLeftIcon extends View<RuneUIButtonLeftIconProps> { |
| 45 | + override template() { |
| 46 | + const { icon, ...rest } = this.data; |
| 47 | + return ( |
| 48 | + <span {...rest} {...buttonParts.leftIcon.attrs}> |
| 49 | + {icon} |
| 50 | + </span> |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// Button 컴포넌트의 레이블 |
| 56 | +export interface RuneUIButtonLabelProps extends RuneElement<"span"> { |
| 57 | + children?: RuneChildren; |
| 58 | +} |
| 59 | + |
| 60 | +export class ButtonLabel extends View<RuneUIButtonLabelProps> { |
| 61 | + override template() { |
| 62 | + const { children, ...rest } = this.data; |
| 63 | + return ( |
| 64 | + <span {...rest} {...buttonParts.label.attrs}> |
| 65 | + {children} |
| 66 | + </span> |
| 67 | + ); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// Button 컴포넌트의 오른쪽 아이콘 |
| 72 | +export interface RuneUIButtonRightIconProps extends RuneElement<"span"> { |
| 73 | + icon: RuneView; |
| 74 | +} |
| 75 | + |
| 76 | +export class ButtonRightIcon extends View<RuneUIButtonRightIconProps> { |
| 77 | + override template() { |
| 78 | + const { icon, ...rest } = this.data; |
| 79 | + return ( |
| 80 | + <span {...rest} {...buttonParts.rightIcon.attrs}> |
| 81 | + {icon} |
| 82 | + </span> |
| 83 | + ); |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +export const Button = { |
| 88 | + Root: ButtonRoot, |
| 89 | + Inner: ButtonInner, |
| 90 | + LeftIcon: ButtonLeftIcon, |
| 91 | + Label: ButtonLabel, |
| 92 | + RightIcon: ButtonRightIcon, |
| 93 | +}; |
0 commit comments