Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Icon): replace title attribute with label #880

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions packages/beeq/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ export namespace Components {
* Set the stroke color of the SVG. The value should be a valid value of the palette color
*/
"color"?: string;
/**
* Label for the icon, used for accessibility
*/
"label"?: string;
/**
* Icon name to load. Please check all available icons [here](https://phosphoricons.com/)
*/
Expand Down Expand Up @@ -2413,6 +2417,10 @@ declare namespace LocalJSX {
* Set the stroke color of the SVG. The value should be a valid value of the palette color
*/
"color"?: string;
/**
* Label for the icon, used for accessibility
*/
"label"?: string;
/**
* Icon name to load. Please check all available icons [here](https://phosphoricons.com/)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const meta: Meta = {
argTypes: {
icons: { table: { disable: true } },
color: { control: 'text' },
label: { control: 'text' },
name: { control: 'select', options: [...ICONS_SET] },
size: { control: 'number' },
src: { control: 'text' },
weight: { control: 'select', options: [...ICON_WEIGHT] },
},
args: {
color: 'text--brand',
label: undefined,
size: 24,
src: undefined,
weight: 'regular',
Expand All @@ -39,6 +41,7 @@ type Story = StoryObj;
const Template = (args: Args) => html`
<bq-icon
color=${ifDefined(args.color)}
label=${ifDefined(args.label)}
name=${ifDefined(args.name)}
size=${ifDefined(args.size)}
src=${ifDefined(args.src)}
Expand Down
5 changes: 4 additions & 1 deletion packages/beeq/src/components/icon/bq-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class BqIcon {
// Public Property API
// ========================

/** Label for the icon, used for accessibility */
@Prop({ reflect: true }) label?: string;

/** Set the stroke color of the SVG. The value should be a valid value of the palette color */
@Prop({ reflect: true }) color?: string;

Expand Down Expand Up @@ -125,11 +128,11 @@ export class BqIcon {
return (
<Host style={styles}>
<div
aria-label={this.label ?? `${this.name} icon`}
class="flex h-[var(--bq-icon--size)] w-[var(--bq-icon--size)] text-[color:var(--bq-icon--color)]"
innerHTML={this._svgContent}
part="base"
role="img"
title={`${this.name} icon`}
/>
</Host>
);
Expand Down
17 changes: 10 additions & 7 deletions packages/beeq/src/components/spinner/bq-spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,19 @@ export class BqSpinner {
}

private setIconSize(): void {
if (!this.hasIconSlot || !this.bqIcon) return;

this.bqIcon.size = parseInt(getCSSVariableValue(`bq-spinner--size-${this.size}`, this.el)).toString();
}

private get bqIcon(): HTMLBqIconElement | undefined {
if (!this.hasIconSlot) return;
HamudeHomsi marked this conversation as resolved.
Show resolved Hide resolved

const iconElements = this.iconSlotElem
.querySelector<HTMLSlotElement>(`slot[name="icon"]`)
?.assignedElements({ flatten: true })
.filter((element) => element.nodeName === 'BQ-ICON');
const slot = this.iconSlotElem.querySelector('slot');

iconElements.forEach((element: HTMLBqIconElement) => {
element.size = parseInt(getCSSVariableValue(`bq-spinner--size-${this.size}`, this.el)).toString();
});
return [...slot.assignedElements({ flatten: true })].filter(
(el: Element) => el.tagName.toLocaleLowerCase() === 'bq-icon',
HamudeHomsi marked this conversation as resolved.
Show resolved Hide resolved
)[0] as HTMLBqIconElement;
}

// render() function
Expand Down