Skip to content

Commit

Permalink
fix: support a wider number of sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Feb 24, 2021
1 parent a7ecf4b commit ee44978
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
7 changes: 6 additions & 1 deletion packages/action-button/src/ActionButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PropertyValues,
TemplateResult,
SizedMixin,
ElementSize,
} from '@spectrum-web-components/base';
import { ButtonBase } from '@spectrum-web-components/button';
import buttonStyles from './action-button.css.js';
Expand All @@ -38,6 +39,8 @@ export type LongpressEvent = {
source: 'pointer' | 'keyboard';
};

type ActionButtonSize = Exclude<ElementSize, 'xxl'>;

/**
* @element sp-card
*
Expand Down Expand Up @@ -178,7 +181,9 @@ export class ActionButton extends SizedMixin(ButtonBase) {
buttonContent.unshift(html`
<sp-icon
id="hold-affordance"
class="${holdAffordanceClass[this.size]}"
class="${holdAffordanceClass[
this.size as ActionButtonSize
]}"
>
${CornerTriangle300Icon()}
</sp-icon>
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/sizedMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Constructor<T = Record<string, unknown>> = {
prototype: T;
};

type ElementSize = 's' | 'm' | 'l' | 'xl';
export type ElementSize = 's' | 'm' | 'l' | 'xl' | 'xxl';

export interface SizedElementInterface {
size: ElementSize;
Expand All @@ -29,7 +29,7 @@ export function SizedMixin<T extends Constructor<UpdatingElement>>(
validSizes = ['s', 'm', 'l', 'xl'],
noDefaultSize,
}: {
validSizes?: Partial<ElementSize>[];
validSizes?: ElementSize[];
noDefaultSize?: boolean;
} = {}
): T & Constructor<SizedElementInterface> {
Expand Down
17 changes: 13 additions & 4 deletions packages/checkbox/src/Checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
property,
PropertyValues,
SizedMixin,
ElementSize,
} from '@spectrum-web-components/base';
import { CheckboxBase } from './CheckboxBase.js';
import '@spectrum-web-components/icon/sp-icon.js';
Expand Down Expand Up @@ -62,6 +63,8 @@ const dashIcon = {
xl: Dash300Icon,
};

type CheckboxSize = Exclude<ElementSize, 'xxl'>;

export class Checkbox extends SizedMixin(CheckboxBase) {
@property({ type: Boolean, reflect: true })
public indeterminate = false;
Expand All @@ -80,11 +83,17 @@ export class Checkbox extends SizedMixin(CheckboxBase) {
return html`
${super.render()}
<span id="box">
<sp-icon id="checkmark" class=${checkmarkClass[this.size]}>
${checkmarkIcon[this.size]()}
<sp-icon
id="checkmark"
class=${checkmarkClass[this.size as CheckboxSize]}
>
${checkmarkIcon[this.size as CheckboxSize]()}
</sp-icon>
<sp-icon id="partialCheckmark" class=${dashClass[this.size]}>
${dashIcon[this.size]()}
<sp-icon
id="partialCheckmark"
class=${dashClass[this.size as CheckboxSize]}
>
${dashIcon[this.size as CheckboxSize]()}
</sp-icon>
</span>
<label id="label"><slot></slot></label>
Expand Down
7 changes: 6 additions & 1 deletion packages/picker/src/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
nothing,
ifDefined,
SizedMixin,
ElementSize,
} from '@spectrum-web-components/base';

import pickerStyles from './picker.css.js';
Expand Down Expand Up @@ -50,6 +51,8 @@ const chevronClass = {
xl: 'spectrum-UIIcon-ChevronDown300',
};

type PickerSize = Exclude<ElementSize, 'xxl'>;

/**
* @element sp-picker
* @slot label - The placeholder content for the picker
Expand Down Expand Up @@ -315,7 +318,9 @@ export class PickerBase extends SizedMixin(Focusable) {
<sp-icon-alert class="validationIcon"></sp-icon-alert>
`
: nothing}
<sp-icon class="icon picker ${chevronClass[this.size]}">
<sp-icon
class="icon picker ${chevronClass[this.size as PickerSize]}"
>
${Chevron100Icon()}
</sp-icon>
`,
Expand Down
5 changes: 4 additions & 1 deletion packages/split-button/src/SplitButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
query,
ifDefined,
SizedMixin,
ElementSize,
} from '@spectrum-web-components/base';

import '@spectrum-web-components/button/sp-button.js';
Expand All @@ -37,6 +38,8 @@ const chevronClass = {
xl: 'spectrum-UIIcon-ChevronDown300',
};

type SplitButtonSize = Exclude<ElementSize, 'xxl'>;

/**
* @slot options - The menu with options that will display when the picker is open
*/
Expand Down Expand Up @@ -141,7 +144,7 @@ export class SplitButton extends SizedMixin(PickerBase) {
>
<sp-icon
class="icon ${this.type === 'field'
? chevronClass[this.size]
? chevronClass[this.size as SplitButtonSize]
: ''}"
>
${this.type === 'field'
Expand Down

0 comments on commit ee44978

Please sign in to comment.