remove base from icons

pull/1006/head
Cory LaViska 2022-11-10 11:30:42 -05:00
rodzic ed45f52433
commit c6a43ba4c2
3 zmienionych plików z 17 dodań i 15 usunięć

Wyświetl plik

@ -12,6 +12,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis
- 🚨 BREAKING: Removed the `fieldset` property from `<sl-radio-group>` (use CSS parts if you want to keep the border) [#965](https://github.com/shoelace-style/shoelace/issues/965)
- 🚨 BREAKING: Removed `base` and `label` parts from `<sl-radio-group>` (use `form-control` and `form-control__label` instead) [#965](https://github.com/shoelace-style/shoelace/issues/965)
- 🚨 BREAKING: Removed the `base` part from `<sl-icon>` (style the host element instead)
- Added `button--checked` to `<sl-radio-button>` and `control--checked` to `<sl-radio>` to style just the checked state [#933](https://github.com/shoelace-style/shoelace/pull/933)
- Added tests for `<sl-menu-item>` and `<sl-menu-label>` [#935](https://github.com/shoelace-style/shoelace/pull/935)
- Added translations for Turkish, English (United Kingdom) and German (Austria) [#989](https://github.com/shoelace-style/shoelace/pull/989)

Wyświetl plik

@ -12,7 +12,6 @@ export default css`
box-sizing: content-box !important;
}
.icon,
svg {
display: block;
height: 100%;

Wyświetl plik

@ -1,6 +1,5 @@
import { html } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
import ShoelaceElement from '../../internal/shoelace-element';
import { watch } from '../../internal/watch';
@ -19,8 +18,6 @@ let parser: DOMParser;
*
* @event sl-load - Emitted when the icon has loaded.
* @event sl-error - Emitted when the icon fails to load due to an error.
*
* @csspart base - The component's internal wrapper.
*/
@customElement('sl-icon')
export default class SlIcon extends ShoelaceElement {
@ -71,6 +68,21 @@ export default class SlIcon extends ShoelaceElement {
this.setIcon();
}
@watch('label')
handleLabelChange() {
const hasLabel = typeof this.label === 'string' && this.label.length > 0;
if (hasLabel) {
this.setAttribute('role', 'img');
this.setAttribute('aria-label', this.label);
this.removeAttribute('aria-hidden');
} else {
this.removeAttribute('role');
this.removeAttribute('aria-label');
this.setAttribute('aria-hidden', 'true');
}
}
@watch('name')
@watch('src')
@watch('library')
@ -120,17 +132,7 @@ export default class SlIcon extends ShoelaceElement {
}
render() {
const hasLabel = typeof this.label === 'string' && this.label.length > 0;
return html` <div
part="base"
class="icon"
role=${ifDefined(hasLabel ? 'img' : undefined)}
aria-label=${ifDefined(hasLabel ? this.label : undefined)}
aria-hidden=${ifDefined(hasLabel ? undefined : 'true')}
>
${unsafeSVG(this.svg)}
</div>`;
return html` ${unsafeSVG(this.svg)} `;
}
}