Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.3.1] - 2026-04-10

### Added
- Add shared stylesheet for custom buttons

## [v0.3.0] - 2026-04-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion createSheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ globalThis.reportError ??= console.error;
const scripts = [
'./animations.js', './button.js', './forms.js', './misc.js', './properties.js', './reset.js',
'./scrollbar.js', './styles.js', './theme.js', './properties-legacy.js', './presentation.js',
'./layers.js',
'./layers.js', './custom-button.js',
];

class CSSStyleSheet {
Expand Down
36 changes: 36 additions & 0 deletions custom-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { css } from '@aegisjsproject/parsers/css.js';

const DISABLED_SELECTOR = ':state(disabled)';

export const customButton = css`@layer components.aegisjsproject.button {
:host {
display: inline flow-root;
appearance: button;
user-select: none;
white-space: nowrap;
align-items: flex-start;
text-align: center;
cursor: default;
box-sizing: border-box;
background-color: ButtonFace;
color: ButtonText;
border: 1px outset ButtonBorder;
border-radius: 2px;
padding: 2px 6px;
font-family: system-ui, -apple-system, sans-serif;
}

:host(${DISABLED_SELECTOR}) {
color: GrayText;
border-color: color-mix(in srgb, GrayText, transparent 50%);
background-color: color-mix(in srgb, ButtonFace, transparent 50%);
}

:host(:hover:not(${DISABLED_SELECTOR})) {
background-color: color-mix(in srgb, ButtonFace, ButtonText 10%);
}

:host(:active:not(${DISABLED_SELECTOR})) {
background-color: color-mix(in srgb, ButtonFace, ButtonText 20%);
}
}`;
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aegisjsproject/styles",
"version": "0.3.0",
"version": "0.3.1",
"description": "Pre-made and reusable styles for `@aegisjsproject/core`",
"keywords": [
"aegis",
Expand Down
1 change: 1 addition & 0 deletions styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { reset } from './reset.js';
export * from './properties.js';
export * from './theme.js';
export * from './button.js';
export { customButton } from './custom-button.js';
export * from './misc.js';
export * from './forms.js';
export * from './scrollbar.js';
Expand Down
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script type="module" referrerpolicy="no-referrer" src="./index.js"></script>
</head>
<body>
<test-button><span slot="content">Custom Button</span></test-button>
<button type="button" id="toggle" class="btn btn-primary" data-background-color="green" data-color="gray" data-border-color="yellow" data-border-width="3" data-border-radius="8">Toggle Theme</button>
<button type="button" popovertarget="popover" popovertargetaction="toggle" class="btn btn-success">Toggle Popover</button>
<div class="inline-block" data-width="3" data-aspect-ratio="2" data-background-color="red" data-rotate="45" data-border-style="solid" data-border-color="green" data-border-radius="8"></div>
Expand Down
45 changes: 25 additions & 20 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import theme from '../css/theme.css' with { type: 'css' };
import btn from '../css/button.css' with { type: 'css' };
import layers from '../css/layers.css' with { type: 'css' };
import animations from '../css/animations.css' with { type: 'css' };
import customButton from '../css/custom-button.css' with { type: 'css' };

const { reset } = await import('@aegisjsproject/styles');

// document.head.append(await sheetToLink(propertiesLegacy));
Expand Down Expand Up @@ -68,38 +70,41 @@ customElements.define('test-el', class TestElement extends HTMLElement {
});

customElements.define('test-button', class TestButton extends HTMLElement {
#shadow;
#internals;
#shadow = this.attachShadow({ mode: 'open' });
#internals = this.attachInternals();

constructor() {
super();
this.#shadow = this.attachShadow({ mode: 'open' });
this.#internals = this.attachInternals();
connectedCallback() {
const slot = document.createElement('slot');
slot.name = 'content';
slot.textContent = 'No content';
this.#shadow.append(slot);
this.#internals.role = 'button';
this.tabIndex = 0;
this.classList.add('btn', 'btn-primary');

Promise.all([
new CSSStyleSheet().replace(`:host {
appearance: button;
background-color: ButtonFace;
color: ButtonText;
border: 1px solid ButtonBorder;
padding: 2px 4px;
border-radius: 4px;
}`),
]).then(sheets => this.#shadow.adoptedStyleSheets = sheets);
this.#shadow.adoptedStyleSheets = [layers, customButton];

this.addEventListener('keydown', event => {
if (event.key === ' ' || event.key === 'Enter') {
event.preventDefault();
event.currentTarget.click();
}
});

this.addEventListener('click', ({ currentTarget }) => {
if (currentTarget.classList.contains('btn')) {
currentTarget.classList.remove('btn', 'btn-primary');
} else {
currentTarget.classList.add('btn', 'btn-primary');
}
});
}

attributeChangedCallback(name, oldVal, newVal) {
if (typeof newVal === 'string') {
this.#internals.states.add('--disabled');
this.#internals.states.add('disabled');
this.inert = true;
} else {
this.#internals.states.delete('--disabled');
this.#internals.states.delete('disabled');
this.inert = false;
}
}

Expand Down
Loading