-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from m-akinc/avoid-invalid-part-selector
Avoid invalid `::part` selector
- Loading branch information
Showing
6 changed files
with
130 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react" | ||
|
||
export const ShadowRoot = ({ label = "Hello from shadow DOM" }) => { | ||
const ref = React.useRef() | ||
|
||
React.useEffect(() => { | ||
if (!ref.current.attachShadow) return | ||
ref.current.attachShadow({ mode: "closed" }) | ||
ref.current.shadowRoot.innerHTML = ` | ||
<button part="foo">${label}</button> | ||
` | ||
ref.current.innerHTML = ` | ||
<style> | ||
::part(foo) { | ||
font-family: "Nunito Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
font-weight: 700; | ||
border: 0; | ||
border-radius: 3em; | ||
cursor: pointer; | ||
display: inline-block; | ||
line-height: 1; | ||
color: white; | ||
background-color: tomato; | ||
font-size: 14px; | ||
padding: 11px 20px; | ||
} | ||
::part(foo):hover { | ||
text-decoration: underline; | ||
} | ||
::part(foo):focus { | ||
box-shadow: inset 0 0 0 2px maroon; | ||
outline: 0; | ||
} | ||
::part(foo):active { | ||
background-color: firebrick; | ||
} | ||
</style> | ||
` | ||
}, []) | ||
|
||
return <div ref={ref} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react" | ||
|
||
import { ShadowRoot } from "./ShadowRootWithPart" | ||
import "./grid.css" | ||
|
||
export default { | ||
title: "Example/ShadowRootWithPart", | ||
component: ShadowRoot, | ||
} | ||
|
||
const Template = () => <ShadowRoot /> | ||
|
||
export const All = () => ( | ||
<div className="story-grid"> | ||
<div> | ||
<ShadowRoot label="Normal" /> | ||
</div> | ||
<div className="pseudo-hover-all"> | ||
<ShadowRoot label="Hover" /> | ||
</div> | ||
<div className="pseudo-focus-all"> | ||
<ShadowRoot label="Focus" /> | ||
</div> | ||
<div className="pseudo-active-all"> | ||
<ShadowRoot label="Active" /> | ||
</div> | ||
<div className="pseudo-hover-all pseudo-focus-all"> | ||
<ShadowRoot label="Hover Focus" /> | ||
</div> | ||
<div className="pseudo-hover-all pseudo-active-all"> | ||
<ShadowRoot label="Hover Active" /> | ||
</div> | ||
<div className="pseudo-focus-all pseudo-active-all"> | ||
<ShadowRoot label="Focus Active" /> | ||
</div> | ||
<div className="pseudo-hover-all pseudo-focus-all pseudo-active-all"> | ||
<ShadowRoot label="Hover Focus Active" /> | ||
</div> | ||
</div> | ||
) | ||
|
||
export const Default = Template.bind() | ||
|
||
export const Hover = Template.bind() | ||
Hover.parameters = { pseudo: { hover: true } } | ||
|
||
export const Focus = Template.bind() | ||
Focus.parameters = { pseudo: { focus: true } } | ||
|
||
export const Active = Template.bind() | ||
Active.parameters = { pseudo: { active: true } } |