Skip to content

Commit c8c1a73

Browse files
committed
fix(react-github-corners): fix position issue.
1 parent 9810063 commit c8c1a73

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

react/src/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ export default function githubCorners(props: GitHubCornersProps) {
5151
styl.top = 0;
5252
}
5353
return (
54-
<github-corners target="__blank" width={size} height={size} href={props.href} position={fixed ? 'fixed' : 'absolute'} z-index={zIndex} style={style} fill={bgColor} color={color} {...styl} {...otherProps}></github-corners>
54+
<github-corners
55+
target="__blank"
56+
width={size}
57+
height={size}
58+
href={props.href}
59+
position={fixed ? 'fixed' : 'absolute'}
60+
z-index={zIndex}
61+
style={style}
62+
fill={bgColor}
63+
color={color}
64+
{...styl}
65+
{...otherProps}
66+
/>
5567
);
5668
}

web-component/src/index.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,30 @@ export class GithubCorners extends HTMLElement {
6969
}
7070
constructor() {
7171
super();
72-
this.initDom();
73-
}
74-
private initDom() {
7572
this.shadow = this.attachShadow({ mode: 'open' });
7673
this.shadow.appendChild(this.ownerDocument.importNode(TEMPLATE.content, true));
77-
this.update();
74+
this.update()
75+
}
76+
private setAttr(name: string, value: string) {
77+
const svg = this.shadow.querySelector('svg');
78+
if (/(color|fill)/.test(name.toLocaleLowerCase())) {
79+
(svg.firstElementChild as HTMLAnchorElement).style[name as any] = value;
80+
} else if (/(z-index|height|width|position|top|left|right|bottom|transform)/.test(name.toLocaleLowerCase())) {
81+
svg.style[name as any] = value;
82+
} else {
83+
svg.setAttribute(name, value);
84+
}
7885
}
7986
private update() {
80-
const svg = this.shadow.querySelector('svg')
8187
;[...this.getAttributeNames(), 'right'].forEach((name) => {
8288
const value = this.getAttribute(name) || this[name as keyof GithubCorners] as any || '';
83-
if (/(z-index|height|width|color|fill|position|top|left|right|bottom|transform)/.test(name.toLocaleLowerCase())) {
84-
svg.style[name as any] = value;
85-
} else {
86-
svg.setAttribute(name, value);
87-
}
89+
this.setAttr(name, value);
8890
});
8991
}
90-
connectedCallback() {
91-
this.update()
92-
}
9392
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
94-
this.update()
93+
if (oldValue !== newValue) {
94+
this.setAttr(name, newValue);
95+
}
9596
}
9697
}
9798

website/src/App.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ body {
5858
}
5959

6060
.App-button button.select {
61+
color: #333;
6162
text-shadow: 0 1px hsl(0deg 0% 100% / 90%), 0 -1px hsl(0deg 0% 100% / 90%), 1px 0px hsl(0deg 0% 100% / 90%), -1px 0px hsl(0deg 0% 100% / 90%)
6263
}
6364
.App-button button {

0 commit comments

Comments
 (0)