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

Icon button variations #898

Open
wants to merge 16 commits into
base: apps.humanatlas.io
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
6 changes: 3 additions & 3 deletions libs/design-system/footer/src/lib/footer.component.stories.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { provideHttpClient } from '@angular/common/http';
import { provideIcons } from '@hra-ui/cdk/icons';
import { provideDesignSystem } from '@hra-ui/design-system';
import { applicationConfig, Meta, StoryObj } from '@storybook/angular';

import { FooterComponent } from './footer.component';

const meta: Meta<FooterComponent> = {
component: FooterComponent,
title: 'FooterComponent',
decorators: [
applicationConfig({
providers: [provideHttpClient(), provideIcons()],
providers: [provideDesignSystem()],
}),
],
};
Expand Down
1 change: 1 addition & 0 deletions libs/design-system/icon-button/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './lib/icon-button-size/icon-button-size.directive';
export * from './lib/icon-button-variant/icon-button-variant.directive';
export * from './lib/providers';
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
button[mat-icon-button] {
button[mat-icon-button],
a[mat-icon-button] {
--mat-icon-button-hover-state-layer-opacity: 0.08;
--mat-icon-button-pressed-state-layer-opacity: 0.16;
--mat-icon-button-state-layer-color: var(--sys-secondary);
--mat-icon-button-focus-state-layer-opacity: 0;
--mdc-icon-button-icon-color: var(--sys-on-tertiary-fixed);

&:focus-visible {
outline: 2px solid var(--sys-tertiary);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this entire block after the variant selectors at line 30 to give it higher priority. Currently the icon color does not change when focused

--mdc-icon-button-icon-color: var(--sys-secondary);
border: 2px solid var(--sys-tertiary);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change back to using outline. Using border causes a layout shift making the icon move slightly

mat-icon {
left: -2px;
top: -2px;
}
}

mat-icon {
height: var(--mdc-icon-button-icon-size);
width: var(--mdc-icon-button-icon-size);
font-size: var(--mdc-icon-button-icon-size);
}

&.icon-button-variant-light {
--mdc-icon-button-icon-color: var(--sys-on-primary);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ripple colors need to be changed to match the spec

}

&.icon-button-variant-dark {
--mdc-icon-button-icon-color: var(--sys-secondary);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Directive, input } from '@angular/core';

/** Input options for icon button color */
export type IconButtonVariant = 'light' | 'dark' | 'default';

/**
* Directive for icon button variants (color)
*/
@Directive({
selector: '[hraIconButtonVariant]',
standalone: true,
host: {
'[class]': '"icon-button-variant-" + variant()',
},
})
export class IconButtonVariantDirective {
/** Input for icon button color variant */
readonly variant = input<IconButtonVariant>('default', { alias: 'hraIconButtonVariant' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the default value to dark. It seems to be the most commonly used version across the apps. Let's also change the string default to color since it is no longer the default

}
27 changes: 12 additions & 15 deletions libs/design-system/icon-button/src/lib/icon-button.stories.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add stories show casing the different variants

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { provideHttpClient } from '@angular/common/http';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { provideIcons } from '@hra-ui/cdk/icons';
import { applicationConfig, moduleMetadata, type Meta, type StoryObj } from '@storybook/angular';
import { provideDesignSystem } from '@hra-ui/design-system';
import { applicationConfig, Meta, moduleMetadata, StoryObj } from '@storybook/angular';

import { IconButtonSizeDirective } from './icon-button-size/icon-button-size.directive';
import { provideIconButtons } from './providers';
import { IconButtonVariantDirective } from './icon-button-variant/icon-button-variant.directive';

const meta: Meta = {
title: 'IconButton',
Expand All @@ -17,6 +17,7 @@ const meta: Meta = {
args: {
icon: 'search',
size: 'large',
variant: 'black',
},
argTypes: {
icon: {
Expand All @@ -26,27 +27,23 @@ const meta: Meta = {
control: 'select',
options: ['small', 'large'],
},
variant: {
control: 'select',
options: ['light', 'dark', 'default'],
},
},
decorators: [
applicationConfig({
providers: [
provideHttpClient(),
provideIcons({
fontIcons: {
defaultClasses: ['material-symbols-rounded'],
},
}),
provideIconButtons(),
],
providers: [provideDesignSystem()],
}),
moduleMetadata({
imports: [MatButtonModule, MatIconModule, IconButtonSizeDirective],
imports: [MatButtonModule, MatIconModule, IconButtonSizeDirective, IconButtonVariantDirective],
}),
],
render: (args) => ({
props: args,
template: `
<button mat-icon-button hraIconButtonSize="${args['size']}">
<button mat-icon-button hraIconButtonSize="${args['size']}" hraIconButtonVariant="${args['variant']}">
<mat-icon>${args['icon']}</mat-icon>
</button>
`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<a [href]="link()" target="_blank" rel="noopener noreferrer">
<a
mat-icon-button
[hraIconButtonVariant]="variant()"
[hraIconButtonSize]="size()"
[href]="link()"
target="_blank"
rel="noopener noreferrer"
>
@if (name() === 'email') {
<mat-icon [class.small]="size() === 'small'">email</mat-icon>
<mat-icon>email</mat-icon>
} @else {
<mat-icon [class.small]="size() === 'small'" [svgIcon]="icon()"></mat-icon>
<mat-icon [svgIcon]="icon()"></mat-icon>
}
</a>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ describe('SocialMediaButtonComponent', () => {
providers: [provideIcons(), provideHttpClient()],
});
const link = screen.getByRole('link');
const icon = link.querySelector('mat-icon');
const icon = link.querySelector('a');
if (icon) {
expect(icon.classList.contains('small')).toBeTruthy();
expect(icon.clientHeight).toBe(24);
}
});

Expand All @@ -28,9 +28,9 @@ describe('SocialMediaButtonComponent', () => {
providers: [provideIcons(), provideHttpClient()],
});
const link = screen.getByRole('link');
const icon = link.querySelector('mat-icon');
const icon = link.querySelector('a');
if (icon) {
expect(icon.classList.contains('small')).not.toBeTruthy();
expect(icon.clientHeight).toBe(40);
}
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import {
IconButtonSize,
IconButtonSizeDirective,
IconButtonVariant,
IconButtonVariantDirective,
} from '@hra-ui/design-system/icon-button';

/** Social media name type */
export type SocialMediaName = 'x' | 'facebook' | 'instagram' | 'youtube' | 'linkedin' | 'email' | 'github';
/** Button size type */
export type SocialMediaButtonSize = 'small' | 'large';

/** All CNS links */
export const SOCIAL_LINKS: Record<SocialMediaName, string> = {
Expand All @@ -14,8 +19,8 @@ export const SOCIAL_LINKS: Record<SocialMediaName, string> = {
instagram: 'https://www.instagram.com/cns_at_iu/',
youtube: 'https://www.youtube.com/@CNSCenter/',
linkedin: 'https://www.linkedin.com/company/cns-indiana-university-bloomington',
email: 'mailto:[email protected]',
github: 'https://github.com/hubmapconsortium/hra-ui',
email: 'mailto:[email protected]',
};

/**
Expand All @@ -24,17 +29,19 @@ export const SOCIAL_LINKS: Record<SocialMediaName, string> = {
@Component({
selector: 'hra-social-media-button',
standalone: true,
imports: [CommonModule, MatIconModule],
imports: [CommonModule, MatButtonModule, MatIconModule, IconButtonVariantDirective, IconButtonSizeDirective],
templateUrl: './social-media-button.component.html',
styleUrl: './social-media-button.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SocialMediaButtonComponent {
/** Button name */
readonly name = input.required<SocialMediaName>();

/** Button size */
readonly size = input.required<SocialMediaButtonSize>();
readonly size = input<IconButtonSize>('large');

/** Button variant */
readonly variant = input<IconButtonVariant>('default');

/** Icon to display */
protected icon = computed(() => `social:${this.name()}`);
Expand Down
Loading