Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
Do not render Tags if values prop is empty
Browse files Browse the repository at this point in the history
Fixes #674
  • Loading branch information
maiertech committed Jan 19, 2021
1 parent 933fa0b commit 43a70eb
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 301 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-badgers-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@undataforum/components': minor
---

Do not render Tags if values prop is empty
18 changes: 12 additions & 6 deletions docs/content/components/tags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ You can adjust the gap:
/>
```

If you provide an empty `values` array, the component will not be rendered:

```jsx live
<Tags values={[]} gap={1} m={2} />
```

## System props

`Tags` supports [space props](https://styled-system.com/api#space) and
Expand All @@ -184,12 +190,12 @@ You can adjust the gap:

## Component props

| Name | Type | Default | Required | Description |
| :------ | :------------------------- | :------------- | :------- | :------------------------------------- |
| values | Array of string | || Array of badge names. |
| gap | Number | 2 | | Gap between badges (from space scale). |
| align | `start`, `center` or `end` | `start` | | Alignment (responsive). |
| variant | String | `tags.primary` | | Optional variant for customizations. |
| Name | Type | Default | Required | Description |
| :------ | :------------------------- | :------------- | :------- | :----------------------------------------------------------- |
| values | Array of shape | || Array of objects. Each object has a `tag` and a `path` prop. |
| gap | Number | 2 | | Gap between badges (from space scale). |
| align | `start`, `center` or `end` | `start` | | Alignment (responsive). |
| variant | String | `tags.primary` | | Optional variant for customizations. |

## Variants

Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@undataforum/assets": "*",
"@undataforum/components": "*",
"@undataforum/preset": "*",
"gatsby": "^2.30.1",
"gatsby": "^2.31.0",
"prop-types": "^15.7.2",
"react": "^16.14.0",
"react-dom": "^16.14.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@maiertech/eslint-config": "^0.16.0",
"@maiertech/prettier-config": "^0.3.0",
"@skypack/package-check": "^0.2.2",
"eslint": "^7.17.0",
"husky": "^4.3.7",
"eslint": "^7.18.0",
"husky": "^4.3.8",
"lint-staged": "^10.5.2",
"microbundle": "^0.13.0",
"micromatch": "^4.0.2",
Expand Down
72 changes: 38 additions & 34 deletions packages/components/src/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,47 @@ const Tags = ({
align = 'start',
variant = 'tags.primary',
...props
}) => (
<Box {...props}>
<Flex
sx={{
// flexDirection: 'row',
justifyContent: normalizeAlign(align),
// alignItems: 'stretch',
flexWrap: 'wrap',
mr: -gap,
mb: -gap,
}}
>
{values.map(({ tag, path }) => (
<Link
href={path}
key={tag}
sx={{
textDecoration: 'none',
mr: gap,
mb: gap,
}}
>
<Badge
}) => {
// Do not render component if values array is empty.
if (values.length === 0) return null;
return (
<Box {...props}>
<Flex
sx={{
// flexDirection: 'row',
justifyContent: normalizeAlign(align),
// alignItems: 'stretch',
flexWrap: 'wrap',
mr: -gap,
mb: -gap,
}}
>
{values.map(({ tag, path }) => (
<Link
href={path}
key={tag}
sx={{
// Anything below variant cannot be overridden by this variant.
variant,
display: 'block',
textDecoration: 'none',
mr: gap,
mb: gap,
}}
variant={variant}
>
{tag}
</Badge>
</Link>
))}
</Flex>
</Box>
);
<Badge
sx={{
// Anything below variant cannot be overridden by this variant.
variant,
display: 'block',
}}
variant={variant}
>
{tag}
</Badge>
</Link>
))}
</Flex>
</Box>
);
};

const alignments = ['start', 'center', 'end'];
const alignType = oneOf(alignments);
Expand Down
Loading

1 comment on commit 43a70eb

@vercel
Copy link

@vercel vercel bot commented on 43a70eb Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.