Skip to content

Commit 919998e

Browse files
committed
feat(fieldlabel): black and white static color variants
Add classes for static colors, as defined on the designs. And adds examples of these variants to the documentation.
1 parent 37dac32 commit 919998e

File tree

4 files changed

+87
-5
lines changed

4 files changed

+87
-5
lines changed

components/fieldlabel/index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ governing permissions and limitations under the License.
106106
text-align: end;
107107
}
108108

109+
.spectrum-FieldLabel--staticBlack {
110+
color: var(--spectrum-black);
111+
}
112+
113+
.spectrum-FieldLabel--staticWhite {
114+
color: var(--spectrum-white);
115+
}
116+
109117
/********* Form *********/
110118
.spectrum-Form {
111119
--spectrum-tableform-item-block-spacing: var(--spectrum-spacing-300);

components/fieldlabel/metadata/fieldlabel.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ sections:
88
description: |
99
### x/x/2024 - Version 8.0.0
1010
#### Spectrum 2 release
11-
Field label now uses Spectrum 2 tokens and specifications. The medium size styles are used by default, so the `spectrum-FieldLabel--sizeM` class is no longer necessary and has been removed.
12-
The mod custom property `--mod-disabled-content-color` has been renamed to `--mod-field-label-disabled-content-color`.
11+
Field label now uses Spectrum 2 tokens and specifications. A few notable changes and additions:
12+
- The medium size styles are used by default, so the `spectrum-FieldLabel--sizeM` class is no longer necessary and has been removed.
13+
- Two variant classes have been added for black and white static colors.
14+
- The mod custom property `--mod-disabled-content-color` has been renamed to `--mod-field-label-disabled-content-color`.
1315
1416
### 11/13/2020 - Version 3.0.0
1517
#### T-shirt sizing
@@ -132,3 +134,29 @@ examples:
132134
<div class="spectrum-Textfield is-disabled">
133135
<input id="lifestory8" name="field" value="" class="spectrum-Textfield-input" disabled>
134136
</div>
137+
138+
- id: fieldlabel-static-colors
139+
name: Static colors
140+
markup: |
141+
<div style="background-color: rgb(181, 209, 211); color: rgb(181, 209, 211); padding: 15px 20px;">
142+
<label for="lifestory6" class="spectrum-FieldLabel spectrum-FieldLabel--staticBlack">
143+
Static black label with example background<svg
144+
class="spectrum-Icon spectrum-UIIcon-Asterisk100 spectrum-FieldLabel-requiredIcon" focusable="false" aria-hidden="true">
145+
<use xlink:href="#spectrum-css-icon-Asterisk100" />
146+
</svg>
147+
</label>
148+
<div class="spectrum-Textfield">
149+
<input id="lifestory6" name="field" value="" class="spectrum-Textfield-input">
150+
</div>
151+
</div>
152+
<div style="background-color: rgb(15, 121, 125); color: rgb(15, 121, 125); padding: 15px 20px;">
153+
<label for="lifestory7" class="spectrum-FieldLabel spectrum-FieldLabel--staticWhite">
154+
Static white label with example background<svg
155+
class="spectrum-Icon spectrum-UIIcon-Asterisk100 spectrum-FieldLabel-requiredIcon" focusable="false" aria-hidden="true">
156+
<use xlink:href="#spectrum-css-icon-Asterisk100" />
157+
</svg>
158+
</label>
159+
<div class="spectrum-Textfield">
160+
<input id="lifestory7" name="field" value="" class="spectrum-Textfield-input">
161+
</div>
162+
</div>

components/fieldlabel/stories/fieldlabel.stories.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Import the component markup template
1+
import { html } from "lit";
22
import { Template } from "./template";
33

44
export default {
@@ -54,6 +54,17 @@ export default {
5454
},
5555
control: "boolean",
5656
},
57+
staticColor: {
58+
name: "Static color",
59+
description: "Variants that can be used when a Field label needs to be placed on top of a colored background or a visual.",
60+
type: { name: "string" },
61+
table: {
62+
type: { summary: "string" },
63+
category: "Component",
64+
},
65+
options: ["black", "white"],
66+
control: "select",
67+
},
5768
},
5869
args: {
5970
rootClass: "spectrum-FieldLabel",
@@ -100,4 +111,22 @@ WrappingAndRequired.args = {
100111
alignment: "left",
101112
isRequired: true,
102113
style: { width: "200px" },
114+
};
115+
116+
export const StaticColors = (args) => html`
117+
${Template({
118+
...args,
119+
label: "The black static color class used on a label marked as required",
120+
staticColor: "black",
121+
})}
122+
${Template({
123+
...args,
124+
label: "The white static color class used on a label marked as required",
125+
staticColor: "white",
126+
})}
127+
`;
128+
StaticColors.storyName = "Static colors";
129+
StaticColors.args = {
130+
alignment: "left",
131+
isRequired: true,
103132
};

components/fieldlabel/stories/template.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { html } from "lit";
22
import { classMap } from "lit/directives/class-map.js";
3-
import { styleMap } from "lit/directives/style-map.js";
43
import { ifDefined } from "lit/directives/if-defined.js";
4+
import { styleMap } from "lit/directives/style-map.js";
5+
import { capitalize, lowerCase } from "lodash-es";
56

67
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
78

@@ -17,6 +18,7 @@ export const Template = ({
1718
alignment,
1819
isDisabled,
1920
isRequired,
21+
staticColor,
2022
style = {},
2123
...globals
2224
}) => {
@@ -40,13 +42,14 @@ export const Template = ({
4042
iconName = "Asterisk100";
4143
}
4244

43-
return html`
45+
const labelMarkup = html`
4446
<label
4547
class=${classMap({
4648
[rootClass]: true,
4749
[`${rootClass}--size${size?.toUpperCase()}`]:
4850
typeof size !== "undefined",
4951
[`${rootClass}--${alignment}`]: typeof alignment !== "undefined",
52+
[`${rootClass}--static${capitalize(lowerCase(staticColor))}`]: typeof staticColor !== "undefined",
5053
"is-disabled": isDisabled,
5154
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
5255
})}
@@ -64,4 +67,18 @@ export const Template = ({
6467
: ""}
6568
</label>
6669
`;
70+
71+
// When using the static color variants, wrap the label in an example element with a background color.
72+
return !staticColor
73+
? labelMarkup
74+
: html`
75+
<div
76+
style=${styleMap({
77+
padding: "1rem",
78+
backgroundColor: staticColor === "white" ? "rgb(15, 121, 125)" : staticColor === "black" ? "rgb(181, 209, 211)" : undefined,
79+
})}
80+
</div>
81+
${labelMarkup}
82+
</div>
83+
`;
6784
};

0 commit comments

Comments
 (0)