Skip to content

Commit

Permalink
feat(input, input-number, input-text): add prefix and suffix width cs…
Browse files Browse the repository at this point in the history
…s tokens (#10206)

**Related Issue:**
[#8154](#8154)

## Summary

Add `--calcite-input-prefix-size` and `--calcite-input-suffix-size` css
tokens to allow users to set custom `prefix` and `suffix` widths.
  • Loading branch information
aPreciado88 authored Sep 12, 2024
1 parent f33fd5d commit 7a6ee82
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
reflects,
renders,
t9n,
themed,
} from "../../tests/commonTests";
import { getElementRect, getElementXY, isElementFocused, selectText } from "../../tests/utils";
import { letterKeys, numberKeys } from "../../utils/key";
Expand All @@ -21,6 +22,7 @@ import {
testPostValidationFocusing,
} from "../input/common/tests";
import { assertCaretPosition } from "../../tests/utils";
import { CSS } from "./resources";

describe("calcite-input-number", () => {
const delayFor2UpdatesInMs = 200;
Expand Down Expand Up @@ -1871,4 +1873,26 @@ describe("calcite-input-number", () => {

expect(internalInput.getAttribute("inputmode")).toBe("decimal");
});

describe("theme", () => {
themed(
html`
<calcite-input-number
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-number>
`,
{
"--calcite-input-prefix-size": {
shadowSelector: `.${CSS.prefix}`,
targetProp: "inlineSize",
},
"--calcite-input-suffix-size": {
shadowSelector: `.${CSS.suffix}`,
targetProp: "inlineSize",
},
},
);
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-input-prefix-size: Specifies the component's prefix width.
* @prop --calcite-input-suffix-size: Specifies the component's suffix width.
*/

:host {
@apply block;
}
Expand Down Expand Up @@ -250,10 +259,12 @@ input:focus {
.prefix {
@apply order-2;
border-inline-end-width: theme("borderWidth.0");
inline-size: var(--calcite-input-prefix-size, auto);
}
.suffix {
@apply order-5;
border-inline-start-width: theme("borderWidth.0");
inline-size: var(--calcite-input-suffix-size, auto);
}

// alignment type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
reflects,
renders,
t9n,
themed,
} from "../../tests/commonTests";
import { isElementFocused, selectText } from "../../tests/utils";
import {
Expand All @@ -18,6 +19,7 @@ import {
testWorkaroundForGlobalPropRemoval,
} from "../input/common/tests";
import { assertCaretPosition } from "../../tests/utils";
import { CSS } from "./resources";

describe("calcite-input-text", () => {
describe("labelable", () => {
Expand Down Expand Up @@ -501,4 +503,26 @@ describe("calcite-input-text", () => {
describe("translation support", () => {
t9n("calcite-input-text");
});

describe("theme", () => {
themed(
html`
<calcite-input-text
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-text>
`,
{
"--calcite-input-prefix-size": {
shadowSelector: `.${CSS.prefix}`,
targetProp: "inlineSize",
},
"--calcite-input-suffix-size": {
shadowSelector: `.${CSS.suffix}`,
targetProp: "inlineSize",
},
},
);
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-input-prefix-size: Specifies the component's prefix width.
* @prop --calcite-input-suffix-size: Specifies the component's suffix width.
*/

:host {
@apply block;
}
Expand Down Expand Up @@ -292,10 +301,12 @@ input[type="text"]::-ms-reveal {
.prefix {
@apply order-2;
border-inline-end-width: theme("borderWidth.0");
inline-size: var(--calcite-input-prefix-size, auto);
}
.suffix {
@apply order-5;
border-inline-start-width: theme("borderWidth.0");
inline-size: var(--calcite-input-suffix-size, auto);
}

// alignment type
Expand Down
18 changes: 18 additions & 0 deletions packages/calcite-components/src/components/input/input.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
renders,
hidden,
t9n,
themed,
} from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import { letterKeys, numberKeys } from "../../utils/key";
import { locales, numberStringFormatter } from "../../utils/locale";
import { getElementRect, getElementXY, isElementFocused, selectText } from "../../tests/utils";
import { DEBOUNCE } from "../../utils/resources";
import { assertCaretPosition } from "../../tests/utils";
import { CSS } from "./resources";
import { testHiddenInputSyncing, testPostValidationFocusing, testWorkaroundForGlobalPropRemoval } from "./common/tests";

describe("calcite-input", () => {
Expand Down Expand Up @@ -2109,4 +2111,20 @@ describe("calcite-input", () => {
describe("translation support", () => {
t9n("calcite-input");
});

describe("theme", () => {
themed(
html` <calcite-input placeholder="Placeholder text" prefix-text="prefix" suffix-text="suffix"></calcite-input> `,
{
"--calcite-input-prefix-size": {
shadowSelector: `.${CSS.prefix}`,
targetProp: "inlineSize",
},
"--calcite-input-suffix-size": {
shadowSelector: `.${CSS.suffix}`,
targetProp: "inlineSize",
},
},
);
});
});
11 changes: 11 additions & 0 deletions packages/calcite-components/src/components/input/input.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-input-prefix-size: Specifies the component's prefix width.
* @prop --calcite-input-suffix-size: Specifies the component's suffix width.
*/

:host {
@apply block;
}
Expand Down Expand Up @@ -322,10 +331,12 @@ input[type="time"]::-webkit-clear-button {
.prefix {
@apply order-2;
border-inline-end-width: theme("borderWidth.0");
inline-size: var(--calcite-input-prefix-size, auto);
}
.suffix {
@apply order-5;
border-inline-start-width: theme("borderWidth.0");
inline-size: var(--calcite-input-suffix-size, auto);
}

// alignment type
Expand Down
6 changes: 6 additions & 0 deletions packages/calcite-components/src/custom-theme.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { chips } from "./custom-theme/chips";
import { datePicker } from "./custom-theme/date-picker";
import { dropdown } from "./custom-theme/dropdown";
import { icon } from "./custom-theme/icon";
import { input, inputTokens } from "./custom-theme/input";
import { inputNumber } from "./custom-theme/input-number";
import { inputText } from "./custom-theme/input-text";
import { loader } from "./custom-theme/loader";
import { notices } from "./custom-theme/notice";
import { pagination } from "./custom-theme/pagination";
Expand Down Expand Up @@ -96,6 +99,7 @@ const kitchenSink = (args: Record<string, string>, useTestValues = false) =>
<div style="width: 40px; height: 40px;">${actionMenu}</div>
${icon}
</div>
${input} ${inputNumber} ${inputText}
</div>
<div class="demo-column">
<div>${card}</div>
Expand All @@ -119,6 +123,7 @@ export default {
...actionPadTokens,
...actionGroupTokens,
...cardTokens,
...inputTokens,
},
};

Expand All @@ -135,6 +140,7 @@ export const theming_TestOnly = (): string => {
...actionPadTokens,
...actionGroupTokens,
...cardTokens,
...inputTokens,
},
true,
);
Expand Down
7 changes: 7 additions & 0 deletions packages/calcite-components/src/custom-theme/input-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { html } from "../../support/formatting";

export const inputNumber = html`<calcite-input-number
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-number>`;
7 changes: 7 additions & 0 deletions packages/calcite-components/src/custom-theme/input-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { html } from "../../support/formatting";

export const inputText = html`<calcite-input-text
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input-text>`;
12 changes: 12 additions & 0 deletions packages/calcite-components/src/custom-theme/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { html } from "../../support/formatting";

export const inputTokens = {
calciteInputPrefixSize: "",
calciteInputSuffixSize: "",
};

export const input = html`<calcite-input
placeholder="Placeholder text"
prefix-text="prefix"
suffix-text="suffix"
></calcite-input>`;

0 comments on commit 7a6ee82

Please sign in to comment.