Skip to content

Commit c7159d8

Browse files
committed
feat(button): add noWrap property
1 parent c8e9f8e commit c7159d8

File tree

13 files changed

+114
-22
lines changed

13 files changed

+114
-22
lines changed

.eslintrc.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"root": true,
3-
"plugins": ["notice", "@spectrum-web-components", "import"],
3+
"plugins": [
4+
"notice",
5+
"@spectrum-web-components",
6+
"import",
7+
"require-extensions"
8+
],
49
"env": {
510
"browser": true,
611
"node": true,
@@ -64,7 +69,11 @@
6469
}
6570
]
6671
},
67-
"extends": ["plugin:prettier/recommended", "plugin:lit-a11y/recommended"],
72+
"extends": [
73+
"plugin:prettier/recommended",
74+
"plugin:lit-a11y/recommended",
75+
"plugin:require-extensions/recommended"
76+
],
6877
"overrides": [
6978
{
7079
"files": ["tasks/*", "scripts/*"],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"eslint-plugin-lit-a11y": "^2.2.2",
157157
"eslint-plugin-notice": "^0.9.10",
158158
"eslint-plugin-prettier": "^5.1.3",
159+
"eslint-plugin-require-extensions": "^0.1.3",
159160
"eslint-plugin-storybook": "^0.8.0",
160161
"express": "^4.16.4",
161162
"fast-glob": "^3.2.12",

packages/button/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@spectrum-web-components/shared": "^0.48.0"
9292
},
9393
"devDependencies": {
94-
"@spectrum-css/button": "^13.1.1"
94+
"@spectrum-css/button": "^13.3.0"
9595
},
9696
"types": "./src/index.d.ts",
9797
"customElements": "custom-elements.json",

packages/button/src/Button.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ export class Button extends SizedMixin(ButtonBase, { noDefaultSize: true }) {
156156
this.treatment = quiet ? 'outline' : 'fill';
157157
}
158158

159+
/**
160+
* Disables text wrapping within the button component's label.
161+
* Please note that this option is not a part of the design specification
162+
* and should be used carefully, with consideration of this overflow behavior
163+
* and the readability of the button's content.
164+
*/
165+
@property({ type: Boolean, attribute: 'no-wrap', reflect: true })
166+
public noWrap = false;
167+
159168
public get quiet(): boolean {
160169
return this.treatment === 'outline';
161170
}

packages/button/src/spectrum-button.css

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ governing permissions and limitations under the License.
134134
}
135135

136136
#label {
137-
text-align: center;
138137
place-self: center;
139138
}
140139

@@ -315,6 +314,8 @@ governing permissions and limitations under the License.
315314
--mod-button-padding-label-to-icon,
316315
var(--spectrum-button-padding-label-to-icon)
317316
);
317+
max-inline-size: none;
318+
max-inline-size: var(--mod-button-max-inline-size, none);
318319
min-inline-size: var(
319320
--mod-button-min-width,
320321
var(--spectrum-button-min-width)
@@ -400,6 +401,7 @@ governing permissions and limitations under the License.
400401
--mod-button-line-height,
401402
var(--spectrum-button-line-height)
402403
);
404+
text-align: center;
403405
text-align: var(--mod-button-text-align, center);
404406
align-self: start;
405407
padding-block-start: calc(
@@ -413,6 +415,7 @@ governing permissions and limitations under the License.
413415
}
414416

415417
[name='icon'] + #label {
418+
text-align: start;
416419
text-align: var(--mod-button-text-align-with-icon, start);
417420
}
418421

@@ -512,6 +515,10 @@ governing permissions and limitations under the License.
512515
var(--spectrum-button-content-color-default)
513516
)
514517
);
518+
transition:
519+
border 0.13s linear,
520+
color 0.13s linear,
521+
background-color 0.13s linear;
515522
transition:
516523
border
517524
var(
@@ -639,6 +646,7 @@ governing permissions and limitations under the License.
639646
::slotted([slot='icon']) {
640647
visibility: visible;
641648
opacity: 1;
649+
transition: opacity 0.13s ease-in-out;
642650
transition: opacity
643651
var(
644652
--mod-button-animation-duration,
@@ -650,6 +658,9 @@ governing permissions and limitations under the License.
650658
.spectrum-ProgressCircle {
651659
visibility: hidden;
652660
opacity: 0;
661+
transition:
662+
opacity 0.13s ease-in-out,
663+
visibility 0s linear 0.13s;
653664
transition:
654665
opacity
655666
var(
@@ -673,6 +684,7 @@ governing permissions and limitations under the License.
673684
:host([pending]) .spectrum-ProgressCircle {
674685
visibility: visible;
675686
opacity: 1;
687+
transition: opacity 0.13s ease-in-out;
676688
transition: opacity
677689
var(
678690
--mod-button-animation-duration,
@@ -681,6 +693,12 @@ governing permissions and limitations under the License.
681693
ease-in-out;
682694
}
683695

696+
:host([no-wrap]) #label {
697+
text-overflow: ellipsis;
698+
white-space: nowrap;
699+
overflow: hidden;
700+
}
701+
684702
:host([static='black']),
685703
:host([static='white']) {
686704
--spectrum-button-focus-indicator-color: var(
@@ -691,13 +709,31 @@ governing permissions and limitations under the License.
691709

692710
@media (forced-colors: active) {
693711
:host {
712+
--highcontrast-button-content-color-default: ButtonText;
713+
--highcontrast-button-content-color-hover: ButtonText;
714+
--highcontrast-button-content-color-focus: ButtonText;
715+
--highcontrast-button-content-color-down: ButtonText;
716+
--highcontrast-button-border-color-default: ButtonBorder;
717+
--highcontrast-button-border-color-hover: ButtonBorder;
718+
--highcontrast-button-border-color-focus: ButtonBorder;
719+
--highcontrast-button-border-color-down: ButtonBorder;
720+
--highcontrast-button-background-color-default: ButtonFace;
721+
--highcontrast-button-background-color-hover: ButtonFace;
722+
--highcontrast-button-background-color-down: ButtonFace;
723+
--highcontrast-button-background-color-focus: ButtonFace;
724+
--highcontrast-button-background-color-disabled: ButtonFace;
694725
--highcontrast-button-content-color-disabled: GrayText;
695726
--highcontrast-button-border-color-disabled: GrayText;
696727
--mod-progress-circle-track-border-color: ButtonText;
697728
--mod-progress-circle-track-border-color-over-background: ButtonText;
698729
--mod-progress-circle-thickness: var(
699730
--spectrum-progress-circle-thickness-medium
700731
);
732+
--mod-button-animation-duration: 0s;
733+
}
734+
735+
#label {
736+
forced-color-adjust: none;
701737
}
702738

703739
:host(:focus-visible):after {
@@ -713,17 +749,17 @@ governing permissions and limitations under the License.
713749
:host([variant='accent'][treatment='fill']) {
714750
--highcontrast-button-background-color-default: ButtonText;
715751
--highcontrast-button-content-color-default: ButtonFace;
752+
--highcontrast-button-content-color-hover: HighlightText;
753+
--highcontrast-button-content-color-down: HighlightText;
754+
--highcontrast-button-content-color-focus: HighlightText;
716755
--highcontrast-button-background-color-disabled: ButtonFace;
717756
--highcontrast-button-background-color-hover: Highlight;
718757
--highcontrast-button-background-color-down: Highlight;
719758
--highcontrast-button-background-color-focus: Highlight;
720-
--highcontrast-button-content-color-hover: ButtonFace;
721-
--highcontrast-button-content-color-down: ButtonFace;
722-
--highcontrast-button-content-color-focus: ButtonFace;
723-
}
724-
725-
:host([variant='accent'][treatment='fill']) #label {
726-
forced-color-adjust: none;
759+
--highcontrast-button-border-color-default: ButtonText;
760+
--highcontrast-button-border-color-hover: Highlight;
761+
--highcontrast-button-border-color-focus: Highlight;
762+
--highcontrast-button-border-color-down: Highlight;
727763
}
728764
}
729765

packages/button/src/spectrum-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ const config = {
7070
converter.classToHost(),
7171
converter.classToAttribute('spectrum-Button--quiet'),
7272
converter.classToAttribute('spectrum-Button--emphasized'),
73+
converter.classToAttribute(
74+
'spectrum-Button--noWrap',
75+
'no-wrap'
76+
),
7377
converter.classToAttribute('is-selected', 'selected'),
7478
converter.classToAttribute('is-focused', 'focused'),
7579
converter.classToAttribute('is-pending', 'pending'),

packages/button/stories/button-primary-fill.stories.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
99
OF ANY KIND, either express or implied. See the License for the specific language
1010
governing permissions and limitations under the License.
1111
*/
12-
import { TemplateResult } from '@spectrum-web-components/base';
12+
import { html, TemplateResult } from '@spectrum-web-components/base';
1313
import {
14+
renderButton,
1415
renderButtonSet,
1516
renderIconSizeOverridden,
1617
renderLink,
@@ -54,6 +55,20 @@ export const minWidthButton = (props: Properties): TemplateResult =>
5455

5556
minWidthButton.storyName = 'min-width';
5657

58+
export const noWrapButton = (props: Properties): TemplateResult =>
59+
renderButton({ noWrap, content, ...props });
60+
61+
const noWrap = true;
62+
const content = html`
63+
Really long content that should not wrap, if it does wrap then we have a
64+
problem. Do we have a problem? I hope we don't have a problem. Is this long
65+
enough to show we do not have a problem? Awesome, we do not have a problem.
66+
Really long content that should not wrap, if it does wrap then we have a
67+
problem. Do we have a problem? I hope we don't have a problem. Is this long
68+
enough to show we do not have a problem? Awesome, we do not have a problem.
69+
`;
70+
noWrapButton.storyName = 'no-wrap';
71+
5772
export const link = (props: Properties): TemplateResult => renderLink(props);
5873

5974
link.storyName = 'href';

packages/button/stories/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function renderButton(properties: Properties): TemplateResult {
122122
?icon-only=${properties.iconOnly}
123123
?pending=${!!properties.pending}
124124
?quiet="${!!properties.quiet}"
125+
?no-wrap="${!!properties.noWrap}"
125126
size=${properties.size}
126127
target=${ifDefined(properties.target)}
127128
treatment=${ifDefined(properties.treatment)}

packages/button/stories/template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface Properties {
2727
size?: 's' | 'm' | 'l' | 'xl';
2828
href?: string;
2929
target?: '_blank' | '_parent' | '_self' | '_top';
30+
noWrap?: boolean;
3031
iconOnly?: boolean;
3132
}
3233

tools/.eslintrc.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@
66
"es6": true
77
},
88
"parser": "@typescript-eslint/parser",
9-
"plugins": ["@typescript-eslint", "notice", "@spectrum-web-components"],
9+
"plugins": [
10+
"@typescript-eslint",
11+
"notice",
12+
"@spectrum-web-components",
13+
"require-extensions"
14+
],
1015
"extends": [
1116
"plugin:@typescript-eslint/recommended",
1217
"prettier",
13-
"plugin:lit-a11y/recommended"
18+
"plugin:lit-a11y/recommended",
19+
"plugin:require-extensions/recommended"
1420
],
1521
"rules": {
1622
"no-debugger": 2,
17-
"no-console": ["error", { "allow": ["warn", "error"] }],
23+
"no-console": [
24+
"error",
25+
{
26+
"allow": ["warn", "error"]
27+
}
28+
],
1829
"@spectrum-web-components/prevent-argument-names": [
1930
"error",
2031
["e", "ev", "evt", "err"]

tools/theme/src/Theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
SystemVariant,
2828
ThemeFragmentMap,
2929
ThemeKindProvider,
30-
} from './theme-interfaces';
30+
} from './theme-interfaces.js';
3131
export type { ProvideLang, ThemeFragmentMap, Color, Scale, SystemVariant };
3232
/**
3333
* @element sp-theme

tools/theme/test/theme-devmode.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import '@spectrum-web-components/theme/sp-theme.js';
1414
import { Theme } from '@spectrum-web-components/theme';
1515
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
1616
import { stub } from 'sinon';
17-
import { testForLitDevWarnings } from '../../../test/testing-helpers';
17+
import { testForLitDevWarnings } from '../../../test/testing-helpers.js';
1818

1919
describe('Theme', () => {
2020
testForLitDevWarnings(

yarn.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,10 +5038,10 @@
50385038
resolved "https://registry.yarnpkg.com/@spectrum-css/breadcrumb/-/breadcrumb-9.1.3.tgz#c1ea002a4e1f3f0b792b951b0768b1a35460da8a"
50395039
integrity sha512-BHzCr5Q5f2+CQxSlq8rDM03wzvn9EozoI/xDP4kw5WrWI7gXUmCJc2iHzu94pQuWprSxoEE+wfx+r63VQ9gsOQ==
50405040

5041-
"@spectrum-css/button@^13.1.1":
5042-
version "13.1.1"
5043-
resolved "https://registry.yarnpkg.com/@spectrum-css/button/-/button-13.1.1.tgz#42be27e8f8d03a7af3eca17fb7566ca2b8cc5f24"
5044-
integrity sha512-GyLNIErpuSfES0GftmzGgsBLgzdMd10PVU34TgYuRz9Ad3DeRpfT1PzA9jKDjqXXCtf91tB7lMkYPdUCHcHLgA==
5041+
"@spectrum-css/button@^13.3.0":
5042+
version "13.3.0"
5043+
resolved "https://registry.yarnpkg.com/@spectrum-css/button/-/button-13.3.0.tgz#37690a6768cc9c82544014d1fb3115ef552a51c7"
5044+
integrity sha512-plco8vVj+YiSHZW1LfxWqwmQmKJHd5Ri6XqA47fdF9cU6gGjEvNXd3ZRt8qPI4oZ/RPMPxEkLsgdk44fD5d/Qw==
50455045

50465046
"@spectrum-css/buttongroup@^7.1.1":
50475047
version "7.1.1"
@@ -5349,7 +5349,7 @@
53495349
integrity sha512-rGfd7jqXOdR69bEjrRP58ynuIeJU0czPfwQvzhtCzg7jKVukV+efNHqrs086sC6xutB3W4TF71K/dZMr3oyTyg==
53505350

53515351
"@spectrum-web-components/eslint-plugin@file:./linters/eslint":
5352-
version "0.47.2"
5352+
version "0.48.0"
53535353

53545354
"@storybook/addon-a11y@^7.5.0":
53555355
version "7.6.19"
@@ -12063,6 +12063,11 @@ eslint-plugin-prettier@^5.1.3:
1206312063
prettier-linter-helpers "^1.0.0"
1206412064
synckit "^0.8.6"
1206512065

12066+
eslint-plugin-require-extensions@^0.1.3:
12067+
version "0.1.3"
12068+
resolved "https://registry.yarnpkg.com/eslint-plugin-require-extensions/-/eslint-plugin-require-extensions-0.1.3.tgz#394aeab433f996797a6ceba0a3f75640d4846bc8"
12069+
integrity sha512-T3c1PZ9PIdI3hjV8LdunfYI8gj017UQjzAnCrxuo3wAjneDbTPHdE3oNWInOjMA+z/aBkUtlW5vC0YepYMZIug==
12070+
1206612071
eslint-plugin-storybook@^0.8.0:
1206712072
version "0.8.0"
1206812073
resolved "https://registry.yarnpkg.com/eslint-plugin-storybook/-/eslint-plugin-storybook-0.8.0.tgz#23185ecabdc289cae55248c090f0c1d8fbae6c41"

0 commit comments

Comments
 (0)