Skip to content

Commit 33fb309

Browse files
authored
feat: extendable style
1 parent 260a328 commit 33fb309

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Traefik Hub Button with WebComponents
22

3-
This Project aims to solve the issue to have a Hub buttonin the Traefik dashboard.
3+
This Project aims to solve the issue to have a Hub button in the Traefik dashboard.
44

55
WebComponents are a way to define a custom component that runs as any other HTML component, so it can be used in any framework or even in pure HTML files, after importing the JS file with the component definition.
66

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import HubButton from 'components/HubButton'
22

3-
export const App = () => {
4-
return <HubButton />
3+
export const App = ({ style }: { style?: string }) => {
4+
return <HubButton style={style} />
55
}
66

77
export default App

src/components/HubButton.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import styled from 'styled-components'
22

3+
const parseInlineStyle = (style: string) => {
4+
const template = document.createElement('template')
5+
template.setAttribute('style', style)
6+
return Object.entries(template.style)
7+
.filter(([key]) => !/^[0-9]+$/.test(key))
8+
.filter(([, value]) => Boolean(value))
9+
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
10+
}
11+
312
const StyledButton = styled.a`
413
display: inline-block;
514
padding: 13px 12px;
6-
715
border-radius: 8px;
8-
background-color: #54b4cd;
9-
color: #03192d;
1016
font-size: 1rem;
1117
font-weight: 700;
12-
line-height: 1.38;
1318
text-decoration: none;
14-
19+
background-color: #54b4cd;
20+
color: #ffffff;
1521
position: relative;
1622
1723
label {
@@ -20,14 +26,17 @@ const StyledButton = styled.a`
2026
}
2127
2228
&:hover {
23-
background-color: #7fc7d9;
24-
transition: background-color 0.1s;
29+
filter: brightness(110%);
2530
}
2631
`
2732

28-
const HubButton = () => {
33+
const HubButton = ({ style }: { style?: string }) => {
2934
return (
30-
<StyledButton href="https://traefik.io/upgrade-traefik" target="_blank">
35+
<StyledButton
36+
href="https://traefik.io/upgrade-traefik"
37+
target="_blank"
38+
style={style ? parseInlineStyle(style) : {}}
39+
>
3140
Upgrade
3241
</StyledButton>
3342
)

0 commit comments

Comments
 (0)