Skip to content

Commit 6c6460d

Browse files
committed
add tags
1 parent b4de5bd commit 6c6460d

File tree

3 files changed

+173
-7
lines changed

3 files changed

+173
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Almost all `trunx` components support a `className` prop, in case you need to ap
8080

8181
<img src="./media/trunks.png" height="290"/>
8282

83-
HTML tags related: `A`, `Div`, `P`, `Span`.
83+
HTML tags related: `A`, `Article`, `Div`, `Nav`, `P`, `Span`.
8484

8585
Bulma related:
8686

src/doc_snippets.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ import {
6060
Span,
6161
Tab,
6262
Tabs,
63+
Tag,
64+
Tags,
6365
Textarea,
6466
Title,
6567
classnames,
@@ -299,12 +301,37 @@ export const Snippets: FC = () => (
299301
]}
300302
/>
301303

304+
<Tag color="primary" variant="light" size="medium">
305+
v1.0.0
306+
</Tag>
307+
308+
<Tag color="warning" size="medium">
309+
Hello
310+
<Delete size="small" />
311+
</Tag>
312+
302313
<Tabs>
303314
<Tab isActive>Pictures</Tab>
304315
<Tab>Music</Tab>
305316
<Tab>Videos</Tab>
306317
</Tabs>
307318

319+
<Tags size="large">
320+
<Tag>All</Tag>
321+
<Tag>Medium</Tag>
322+
<Tag>Size</Tag>
323+
</Tags>
324+
325+
<Tags hasAddons>
326+
<Tag>package</Tag>
327+
<Tag color="primary">trunx</Tag>
328+
</Tags>
329+
330+
<Tags hasAddons>
331+
<Tag color="danger">Alex Smith</Tag>
332+
<a className="tag is-delete" />
333+
</Tags>
334+
308335
<Textarea size="small" color="info" />
309336

310337
<Title tag="h1">Title</Title>

src/react.tsx

+145-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const are = (
6666
): Extract<Bulma, `are-${typeof arg}`> | undefined =>
6767
arg ? `are-${arg}` : undefined
6868

69-
export const is = (
69+
const is = (
7070
arg: Color | ColorVariant | Size | undefined,
7171
): Extract<Bulma, `is-${typeof arg}`> | undefined =>
7272
arg ? `is-${arg}` : undefined
@@ -86,6 +86,18 @@ export const A: FC<PropsWithChildren<AProps>> = ({
8686
)
8787
export type AProps = AnchorHTMLAttributes<HTMLAnchorElement> & BulmaProp
8888

89+
export const Article: FC<PropsWithChildren<NavProps>> = ({
90+
bulma,
91+
className,
92+
children,
93+
...props
94+
}) => (
95+
<article className={classnames<Bulma>(className as Bulma, bulma)} {...props}>
96+
{children}
97+
</article>
98+
)
99+
export type ArticleProps = HTMLAttributes<HTMLElement> & BulmaProp
100+
89101
/**
90102
* A breadcrumb component to improve navigation experience.
91103
*
@@ -609,8 +621,7 @@ export const Delete: FC<DeleteProps> = ({
609621
{...props}
610622
/>
611623
)
612-
export type DeleteProps = ButtonHTMLAttributes<HTMLButtonElement> &
613-
SizeProp<"large">
624+
export type DeleteProps = ButtonHTMLAttributes<HTMLButtonElement> & SizeProp
614625

615626
export const Div: FC<PropsWithChildren<DivProps>> = ({
616627
bulma,
@@ -1051,9 +1062,9 @@ export type HeroHeadProps = HTMLAttributes<HTMLDivElement> & BulmaProp
10511062
* @example
10521063
*
10531064
* ```tsx
1054-
* <Icon>
1055-
* <i className="fas fa-home"></i>
1056-
* </Icon>
1065+
* <Icon>
1066+
* <i className="fas fa-home"></i>
1067+
* </Icon>
10571068
* ```
10581069
*
10591070
* @see [bulma docs](https://bulma.io/documentation/elements/icon/).
@@ -1552,6 +1563,18 @@ export const ModalContent: FC<PropsWithChildren<ModalContentProps>> = ({
15521563
)
15531564
export type ModalContentProps = HTMLAttributes<HTMLDivElement> & BulmaProp
15541565

1566+
export const Nav: FC<PropsWithChildren<NavProps>> = ({
1567+
bulma,
1568+
className,
1569+
children,
1570+
...props
1571+
}) => (
1572+
<nav className={classnames<Bulma>(className as Bulma, bulma)} {...props}>
1573+
{children}
1574+
</nav>
1575+
)
1576+
export type NavProps = HTMLAttributes<HTMLElement> & BulmaProp
1577+
15551578
/**
15561579
* A responsive horizontal navbar that can support images, links, buttons, and dropdowns.
15571580
*
@@ -2273,6 +2296,122 @@ export type TabProps = AnchorHTMLAttributes<HTMLAnchorElement> &
22732296
isActive: boolean
22742297
}>
22752298

2299+
/**
2300+
* Small tag labels to insert anywhere.
2301+
*
2302+
* @example
2303+
*
2304+
* ```tsx
2305+
* <Tag color="primary" variant="light">
2306+
* v1.0.0
2307+
* </Tag>
2308+
* ```
2309+
*
2310+
* @example Append a delete button.
2311+
*
2312+
* ```tsx
2313+
* <Tag color="warning" size="medium">
2314+
* Hello
2315+
* <Delete size="small" />
2316+
* </Tag>
2317+
* ```
2318+
*
2319+
* @see [bulma docs](https://bulma.io/documentation/elements/tag/).
2320+
*/
2321+
export const Tag: FC<PropsWithChildren<TagProps>> = ({
2322+
color,
2323+
variant,
2324+
isHoverable,
2325+
isRounded,
2326+
size,
2327+
bulma,
2328+
className,
2329+
children,
2330+
...props
2331+
}) => (
2332+
<span
2333+
className={classnames<Bulma>(
2334+
className as Bulma,
2335+
"tag",
2336+
is(color),
2337+
is(variant),
2338+
is(size),
2339+
{
2340+
"is-hoverable": isHoverable,
2341+
"is-rounded": isRounded,
2342+
},
2343+
bulma,
2344+
)}
2345+
{...props}
2346+
>
2347+
{children}
2348+
</span>
2349+
)
2350+
export type TagProps = HTMLAttributes<HTMLSpanElement> &
2351+
BulmaProp &
2352+
ColorProp &
2353+
ColorVariantProp<"light"> &
2354+
SizeProp<"medium" | "large"> &
2355+
Partial<{
2356+
isHoverable: boolean
2357+
isRounded: boolean
2358+
}>
2359+
2360+
/**
2361+
* List of tags.
2362+
*
2363+
* @example Size.
2364+
*
2365+
* ```tsx
2366+
* <Tags size="large">
2367+
* <Tag>All</Tag>
2368+
* <Tag>Medium</Tag>
2369+
* <Tag>Size</Tag>
2370+
* </Tags>
2371+
* ```
2372+
*
2373+
* @example Attach tags together.
2374+
*
2375+
* ```tsx
2376+
* <Tags hasAddons>
2377+
* <Tag>package</Tag>
2378+
* <Tag color="primary">trunx</Tag>
2379+
* </Tags>
2380+
* ```
2381+
*
2382+
* @example Attach a text tag with a delete tag together.
2383+
*
2384+
* ```tsx
2385+
* <Tags hasAddons>
2386+
* <Tag color="danger">Alex Smith</Tag>
2387+
* <a class="tag is-delete" />
2388+
* </Tags>
2389+
* ```
2390+
*
2391+
* @see [bulma docs](https://bulma.io/documentation/elements/tag/#list-of-tags)
2392+
*/
2393+
export const Tags: FC<PropsWithChildren<TagsProps>> = ({
2394+
hasAddons,
2395+
size,
2396+
className,
2397+
children,
2398+
...props
2399+
}) => (
2400+
<div
2401+
className={classnames<Bulma>(className as Bulma, "tags", are(size), {
2402+
"has-addons": hasAddons,
2403+
})}
2404+
{...props}
2405+
>
2406+
{children}
2407+
</div>
2408+
)
2409+
export type TagsProps = HTMLAttributes<HTMLDivElement> &
2410+
PluralSizeProp &
2411+
Partial<{
2412+
hasAddons: boolean
2413+
}>
2414+
22762415
/**
22772416
* The multiline textarea and its variations.
22782417
*

0 commit comments

Comments
 (0)