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

[DRAFT] Make icons great again!! #4960

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 0 additions & 4 deletions packages/accordion/src/accordion.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ governing permissions and limitations under the License.

@import url('./spectrum-accordion.css');
@import url('./accordion-overrides.css');

:host {
--spectrum-logical-rotation: ;
}
30 changes: 12 additions & 18 deletions packages/checkbox/src/Checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ import { property } from '@spectrum-web-components/base/src/decorators.js';
import { CheckboxMixin } from './CheckboxMixin.js';
import checkboxStyles from './checkbox.css.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark75.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark200.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark300.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-dash75.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-dash100.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-dash200.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-dash300.js';
import checkmarkSmallStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';
import checkmarkSmallOverrides from '@spectrum-web-components/icon/src/icon-checkmark-overrides.css.js';
import dashSmallStyles from '@spectrum-web-components/icon/src/spectrum-icon-dash.css.js';
Expand All @@ -46,26 +40,26 @@ const checkmarkIcon = {
},
m: () => {
return html`
<sp-icon-checkmark100
<sp-icon-checkmark75
id="checkmark"
class="spectrum-Icon spectrum-UIIcon-Checkmark100"
></sp-icon-checkmark100>
></sp-icon-checkmark75>
`;
},
l: () => {
return html`
<sp-icon-checkmark200
<sp-icon-checkmark75
id="checkmark"
class="spectrum-Icon spectrum-UIIcon-Checkmark200"
></sp-icon-checkmark200>
></sp-icon-checkmark75>
`;
},
xl: () => {
return html`
<sp-icon-checkmark300
<sp-icon-checkmark75
id="checkmark"
class="spectrum-Icon spectrum-UIIcon-Checkmark300"
></sp-icon-checkmark300>
></sp-icon-checkmark75>
`;
},
};
Expand All @@ -81,26 +75,26 @@ const dashIcon = {
},
m: () => {
return html`
<sp-icon-dash100
<sp-icon-dash75
id="partialCheckmark"
class="spectrum-Icon spectrum-UIIcon-Dash100"
></sp-icon-dash100>
></sp-icon-dash75>
`;
},
l: () => {
return html`
<sp-icon-dash200
<sp-icon-dash75
id="partialCheckmark"
class="spectrum-Icon spectrum-UIIcon-Dash200"
></sp-icon-dash200>
></sp-icon-dash75>
`;
},
xl: () => {
return html`
<sp-icon-dash300
<sp-icon-dash75
id="partialCheckmark"
class="spectrum-Icon spectrum-UIIcon-Dash300"
></sp-icon-dash300>
></sp-icon-dash75>
`;
},
};
Expand Down
5 changes: 1 addition & 4 deletions packages/icon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
"./src/icon-cross-overrides.css.js": "./src/icon-cross-overrides.css.js",
"./src/icon-dash-overrides.css.js": "./src/icon-dash-overrides.css.js",
"./src/icon-overrides.css.js": "./src/icon-overrides.css.js",
"./src/icon-single-gripper-overrides.css.js": "./src/icon-single-gripper-overrides.css.js",
"./src/icon-triple-gripper-overrides.css.js": "./src/icon-triple-gripper-overrides.css.js",
"./src/icon.css.js": "./src/icon.css.js",
"./src/index.js": {
"development": "./src/index.dev.js",
Expand Down Expand Up @@ -81,8 +79,7 @@
"lit-html"
],
"dependencies": {
"@spectrum-web-components/base": "^1.0.1",
"@spectrum-web-components/iconset": "^1.0.1"
"@spectrum-web-components/base": "^1.0.1"
},
"devDependencies": {
"@spectrum-css/icon": "^8.0.0-s2-foundations.17"
Expand Down
90 changes: 1 addition & 89 deletions packages/icon/src/Icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ governing permissions and limitations under the License.
*/

import { html, TemplateResult } from '@spectrum-web-components/base';
import {
property,
query,
} from '@spectrum-web-components/base/src/decorators.js';
import { property } from '@spectrum-web-components/base/src/decorators.js';
import { ifDefined } from '@spectrum-web-components/base/src/directives.js';

import { IconsetRegistry } from '@spectrum-web-components/iconset/src/iconset-registry.js';

import { IconBase } from './IconBase.js';

/**
Expand All @@ -31,45 +26,6 @@ export class Icon extends IconBase {
@property()
public name?: string;

@query('#container')
private iconContainer?: HTMLElement;

private updateIconPromise?: Promise<void>;

public override connectedCallback(): void {
super.connectedCallback();
window.addEventListener('sp-iconset-added', this.iconsetListener);
}

public override disconnectedCallback(): void {
super.disconnectedCallback();
window.removeEventListener('sp-iconset-added', this.iconsetListener);
}

public override firstUpdated(): void {
this.updateIconPromise = this.updateIcon();
}

public override attributeChangedCallback(
name: string,
old: string,
value: string
): void {
super.attributeChangedCallback(name, old, value);
this.updateIconPromise = this.updateIcon(); // any of our attributes change, update our icon
}

private iconsetListener = (event: CustomEvent): void => {
if (!this.name) {
return;
}
// parse the icon name to get iconset name
const icon = this.parseIcon(this.name);
if (event.detail.name === icon.iconset) {
this.updateIconPromise = this.updateIcon();
}
};

private announceIconImageSrcError(): void {
this.dispatchEvent(
new Event('error', {
Expand All @@ -96,48 +52,4 @@ export class Icon extends IconBase {
}
return super.render();
}

private async updateIcon(): Promise<void> {
if (this.updateIconPromise) {
await this.updateIconPromise;
}
if (!this.name) {
return Promise.resolve();
}
// parse the icon name to get iconset name
const icon = this.parseIcon(this.name);
// try to retrieve the iconset
const iconset = IconsetRegistry.getInstance().getIconset(icon.iconset);
if (!iconset) {
// we can stop here as there's nothing to be done till we get the iconset
return Promise.resolve();
}
if (!this.iconContainer) {
return Promise.resolve();
}
this.iconContainer.innerHTML = '';
return iconset.applyIconToElement(
this.iconContainer,
icon.icon,
this.size || '',
this.label ? this.label : ''
);
}

private parseIcon(icon: string): { iconset: string; icon: string } {
const iconParts = icon.split(':');
let iconsetName = 'default';
let iconName = icon;
if (iconParts.length > 1) {
iconsetName = iconParts[0];
iconName = iconParts[1];
}
return { iconset: iconsetName, icon: iconName };
}

protected override async getUpdateComplete(): Promise<boolean> {
const complete = (await super.getUpdateComplete()) as boolean;
await this.updateIconPromise;
return complete;
}
}
13 changes: 0 additions & 13 deletions packages/icon/src/icon-single-gripper-overrides.css

This file was deleted.

13 changes: 0 additions & 13 deletions packages/icon/src/icon-triple-gripper-overrides.css

This file was deleted.

22 changes: 0 additions & 22 deletions packages/icon/stories/icon.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ export default {
title: 'Icon',
};

export const Medium = (): TemplateResult => {
return html`
<sp-icons-medium></sp-icons-medium>
${sizes.map(
(size) => html`
<sp-icon size=${size} name="ui:Chevron200"></sp-icon>
`
)}
`;
};

export const Large = (): TemplateResult => {
return html`
<sp-icons-large></sp-icons-large>
${sizes.map(
(size) => html`
<sp-icon size=${size} name="ui:Chevron400"></sp-icon>
`
)}
`;
};

export const imageIcon = (): TemplateResult => {
return html`
${sizes.map(
Expand Down
12 changes: 1 addition & 11 deletions packages/menu/src/MenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';
import { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';
import chevronStyles from '@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js';
import chevronIconOverrides from '@spectrum-web-components/icon/src/icon-chevron-overrides.css.js';
import { DependencyManagerController } from '@spectrum-web-components/reactive-controllers/src/DependencyManger.js';

import menuItemStyles from './menu-item.css.js';
import checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';
import checkmarkSmallOverrides from '@spectrum-web-components/icon/src/icon-checkmark-overrides.css.js';
import type { Menu } from './Menu.js';
import { MutationController } from '@lit-labs/observers/mutation-controller.js';
import type { Overlay } from '@spectrum-web-components/overlay';
Expand Down Expand Up @@ -97,13 +93,7 @@ export class MenuItem extends LikeAnchor(
ObserveSlotText(ObserveSlotPresence(Focusable, '[slot="icon"]'))
) {
public static override get styles(): CSSResultArray {
return [
menuItemStyles,
checkmarkStyles,
checkmarkSmallOverrides,
chevronStyles,
chevronIconOverrides,
];
return [menuItemStyles];
}

abortControllerSubmenu!: AbortController;
Expand Down
7 changes: 7 additions & 0 deletions packages/menu/src/menu-item.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ governing permissions and limitations under the License.
:host([no-wrap]) #label {
display: block;
}

sp-icon {
/* I want to decrease the value of --spectrum-icon-size by 6px here to match the
value of icon-size in the snippet from packages/icon/src/icon-**-overrides.css */
block-size: calc(var(--spectrum-icon-size) - 6px);
inline-size: calc(var(--spectrum-icon-size) - 6px);
}
15 changes: 6 additions & 9 deletions packages/textfield/src/Textfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ import {

import { ManageHelpText } from '@spectrum-web-components/help-text/src/manage-help-text.js';
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
import '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';

import textfieldStyles from './textfield.css.js';
import checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';
import checkmarkSmallOverrides from '@spectrum-web-components/icon/src/icon-checkmark-overrides.css.js';

import '@spectrum-web-components/icon/sp-icon.js';
import { Checkmark100Icon } from '@spectrum-web-components/icons-ui';
const textfieldTypes = ['text', 'url', 'tel', 'email', 'password'] as const;
export type TextfieldType = (typeof textfieldTypes)[number];

Expand All @@ -50,7 +48,7 @@ export class TextfieldBase extends ManageHelpText(
})
) {
public static override get styles(): CSSResultArray {
return [textfieldStyles, checkmarkStyles, checkmarkSmallOverrides];
return [textfieldStyles];
}

@state()
Expand Down Expand Up @@ -280,10 +278,9 @@ export class TextfieldBase extends ManageHelpText(
`;
} else if (this.valid) {
return html`
<sp-icon-checkmark100
id="valid"
class="icon spectrum-UIIcon-Checkmark100"
></sp-icon-checkmark100>
<sp-icon id="valid" class="icon" size=${this.size}>
${Checkmark100Icon({ hidden: true })}
</sp-icon>
`;
}
return nothing;
Expand Down
7 changes: 7 additions & 0 deletions packages/textfield/src/textfield.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ textarea {
resize: none;
overflow: hidden;
}

sp-icon {
/* I want to decrease the value of --spectrum-icon-size by 6px here to match the
value of icon-size in the snippet from packages/icon/src/icon-**-overrides.css */
block-size: calc(var(--spectrum-icon-size) - 8px);
inline-size: calc(var(--spectrum-icon-size) - 8px);
}
Loading