-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add new component to toolbar library (#10906)
* feat: progress * chore: changeset
- Loading branch information
1 parent
ddd8e49
commit 7bbd664
Showing
7 changed files
with
168 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"astro": minor | ||
--- | ||
|
||
Adds a new radio checkbox component to the dev toolbar UI library (`astro-dev-toolbar-radio-checkbox`) |
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,5 @@ | ||
--- | ||
"astro": minor | ||
--- | ||
|
||
Adds a new `buttonBorderRadius` property to the `astro-dev-toolbar-button` component for the dev toolbar component library. This property can be useful to make a fully rounded button with an icon in the center. |
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
121 changes: 121 additions & 0 deletions
121
packages/astro/src/runtime/client/dev-toolbar/ui-library/radio-checkbox.ts
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,121 @@ | ||
const styles = ['purple', 'gray', 'red', 'green', 'yellow', 'blue'] as const; | ||
|
||
type RadioStyle = (typeof styles)[number]; | ||
|
||
export class DevToolbarRadioCheckbox extends HTMLElement { | ||
private _radioStyle: RadioStyle = 'purple'; | ||
input: HTMLInputElement; | ||
|
||
shadowRoot: ShadowRoot; | ||
|
||
get radioStyle() { | ||
return this._radioStyle; | ||
} | ||
|
||
set radioStyle(value) { | ||
if (!styles.includes(value)) { | ||
console.error(`Invalid style: ${value}, expected one of ${styles.join(', ')}.`); | ||
return; | ||
} | ||
this._radioStyle = value; | ||
this.updateStyle(); | ||
} | ||
|
||
static observedAttributes = ['radio-style', 'checked', 'disabled', 'name', 'value']; | ||
|
||
constructor() { | ||
super(); | ||
this.shadowRoot = this.attachShadow({ mode: 'open' }); | ||
|
||
this.shadowRoot.innerHTML = ` | ||
<style> | ||
:host { | ||
--purple-unchecked: rgba(224, 204, 250, 0.33); | ||
--purple-checked: rgba(224, 204, 250, 1); | ||
--gray-unchecked: rgba(191, 193, 201, 0.33); | ||
--gray-checked: rgba(191, 193, 201, 1); | ||
--red-unchecked: rgba(249, 196, 215, 0.33); | ||
--red-checked: rgba(179, 62, 102, 1); | ||
--green-unchecked: rgba(213, 249, 196, 0.33); | ||
--green-checked: rgba(61, 125, 31, 1); | ||
--yellow-unchecked: rgba(255, 236, 179, 0.33); | ||
--yellow-checked: rgba(181, 138, 45, 1); | ||
--blue-unchecked: rgba(189, 195, 255, 0.33); | ||
--blue-checked: rgba(54, 69, 217, 1); | ||
} | ||
input[type="radio"] { | ||
appearance: none; | ||
-webkit-appearance: none; | ||
display: flex; | ||
align-content: center; | ||
justify-content: center; | ||
border: 2px solid var(--unchecked-color); | ||
border-radius: 9999px; | ||
width: 16px; | ||
height: 16px; | ||
} | ||
input[type="radio"]::before { | ||
content: ""; | ||
background-color: var(--checked-color); | ||
width: 8px; | ||
height: 8px; | ||
border-radius: 9999px; | ||
visibility: hidden; | ||
margin: 2px; | ||
} | ||
input[type="radio"]:checked { | ||
border-color: var(--checked-color); | ||
} | ||
input[type="radio"]:checked::before { | ||
visibility: visible; | ||
} | ||
</style> | ||
<style id="selected-style"></style> | ||
`; | ||
this.input = document.createElement('input'); | ||
this.input.type = 'radio'; | ||
this.shadowRoot.append(this.input); | ||
} | ||
|
||
connectedCallback() { | ||
this.updateInputState(); | ||
this.updateStyle(); | ||
} | ||
|
||
updateStyle() { | ||
const styleElement = this.shadowRoot.querySelector<HTMLStyleElement>('#selected-style'); | ||
|
||
if (styleElement) { | ||
styleElement.innerHTML = ` | ||
:host { | ||
--unchecked-color: var(--${this._radioStyle}-unchecked); | ||
--checked-color: var(--${this._radioStyle}-checked); | ||
} | ||
`; | ||
} | ||
} | ||
|
||
updateInputState() { | ||
this.input.checked = this.hasAttribute('checked'); | ||
this.input.disabled = this.hasAttribute('disabled'); | ||
this.input.name = this.getAttribute('name') || ''; | ||
this.input.value = this.getAttribute('value') || ''; | ||
} | ||
|
||
attributeChangedCallback() { | ||
if (this.hasAttribute('radio-style')) { | ||
this.radioStyle = this.getAttribute('radio-style') as RadioStyle; | ||
} | ||
|
||
this.updateInputState(); | ||
} | ||
} |