Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple #88

Merged
merged 6 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ The `<ProjectBadge />` component takes five, optional, props:
| abbreviation | String | Short representation of the name. Large font. Typically one uppercase letter, one lowercase. | `"Em"` |
| description | String | Title or brief description. Smaller text, displayed in all-caps. | `"Enzyme Matchers"` |
| className | String | Class to apply directly to the SVG | `"project-badge"` |
| isHoverable | Boolean | Add hover style effects | `true` |
| simple | Boolean | Hides the description and enlarges the abbreviation - use for small badge display | `false` |

It is recommended to at least include the `color`, `description`, and `abbreviation` props.

Expand Down Expand Up @@ -70,13 +72,22 @@ See [featuredLogos](https://github.com/FormidableLabs/formidable-oss-badges/tree
- `groqd`
- `envy`
- `figlog`
- `cloudsplice`
cpresler marked this conversation as resolved.
Show resolved Hide resolved

### Additional props
For a simplified version of the logo without the name in the badge (works better for smaller sizes), you can use the `simple` variant of any of the above options.

| Prop | Type | Description | Default |
| ----------- | ------- | ------------------------ | ------- |
| className | String | Additional class names | `''` |
| isHoverable | Boolean | Add hover style effects | `true` |
```jsx
<FeaturedBadge name="victory" simple />
```

### FeaturedBadge props

| Prop | Type | Description | Default |
| ----------- | ------- | --------------------------------------------------------------------------------- | ------- |
| name | String | One of the available badge names | `''` |
| className | String | Additional class names | `''` |
| isHoverable | Boolean | Add hover style effects | `true` |
| simple | Boolean | Hides the description and enlarges the abbreviation - use for small badge display | `false` |

## Examples (with Images)

Expand Down
19 changes: 11 additions & 8 deletions src/FeaturedBadge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ const Template: ComponentStory<typeof FeaturedBadge> = args => (
)

export const Spectacle = Template.bind({})
Spectacle.args = { name: "spectacle" }
Spectacle.args = { name: "spectacle", simple: false }

export const Groqd = Template.bind({})
Groqd.args = { name: "groqd" }
Groqd.args = { name: "groqd", simple: false }

export const Nuka = Template.bind({})
Nuka.args = { name: "nuka" }
Nuka.args = { name: "nuka", simple: false }

export const ReactNativeOwl = Template.bind({})
ReactNativeOwl.args = { name: "owl" }
ReactNativeOwl.args = { name: "owl", simple: false }

export const Victory = Template.bind({})
Victory.args = { name: "victory" }
Victory.args = { name: "victory", simple: false }

export const Urql = Template.bind({})
Urql.args = { name: "urql" }
Urql.args = { name: "urql", simple: false }

export const Envy = Template.bind({})
Envy.args = { name: "envy" }
Envy.args = { name: "envy", simple: false }

export const FigLog = Template.bind({})
FigLog.args = { name: "figlog" }
FigLog.args = { name: "figlog", simple: false }

export const CloudSplice = Template.bind({})
CloudSplice.args = { name: "cloudsplice", simple: false }
7 changes: 4 additions & 3 deletions src/FeaturedBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ type Props = SVGProps<SVGElement> & {
className?: string
isHoverable?: boolean
style?: CSSProperties
simple?: boolean
}

const FeaturedBadge = ({
name,
className,
style,
isHoverable = true,
simple = false,
...rest
}: Props) => {
const keyName = simple ? `${name.toLowerCase()}Simple` : name.toLowerCase()
const Logo =
featuredLogos.default[
name.toLowerCase() as keyof typeof featuredLogos.default
]
featuredLogos.default[keyName as keyof typeof featuredLogos.default]
if (!Logo) return null

return (
Expand Down
3 changes: 2 additions & 1 deletion src/ProjectBadge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const Template: ComponentStory<typeof ProjectBadge> = args => (

export const ReactLiveBadge = Template.bind({})
ReactLiveBadge.args = {
abbreviation: "RL",
abbreviation: "Re",
description: "React Live",
color: "skyblue",
simple: false,
}
14 changes: 10 additions & 4 deletions src/ProjectBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
className?: string
isHoverable?: boolean
style?: CSSProperties
simple?: boolean
}

const getDescription = (props: Props) => {
Expand Down Expand Up @@ -50,8 +51,13 @@ const ProjectBadge = (props: Props) => {
className,
style,
isHoverable = true,
simple = false,
} = props
const abbrYAxis = includesDescender(abbreviation) ? BASE_Y : BASE_Y + 2
let baseY = BASE_Y
if (simple) {
baseY = 64
}
cpresler marked this conversation as resolved.
Show resolved Hide resolved
const abbrYAxis = includesDescender(abbreviation) ? baseY : baseY + 2
return (
<Fragment>
<svg
Expand Down Expand Up @@ -84,16 +90,16 @@ const ProjectBadge = (props: Props) => {
<text
fill={BLACK}
fontFamily="Helvetica, sans-serif"
fontSize={230}
fontSize={simple ? 280 : 230}
letterSpacing={-5.5}
textAnchor="middle"
x="50%"
x={simple ? "49%" : "50%"}
y={`${abbrYAxis}%`}
>
{abbreviation}
</text>
)}
{getDescription(props)}
{!simple && getDescription(props)}
</g>
</svg>
</Fragment>
Expand Down
Loading
Loading