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

Add interaction stories for buttons, number field, and anchor #1919

Merged
merged 33 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d1adba2
Add pseudo-states storybook addon
m-akinc Mar 11, 2024
23feb19
Add interaction stories for buttons, number field, and anchor
m-akinc Feb 13, 2024
f1171a6
Change files
m-akinc Mar 11, 2024
32dce4b
Feedback
m-akinc Mar 13, 2024
e8831ed
Lint fix
m-akinc Mar 14, 2024
463c357
Feedback
m-akinc Mar 14, 2024
b510032
Improve comments
m-akinc Mar 14, 2024
68420bc
Disable toolbar item for pseudo-states addon
m-akinc Mar 18, 2024
d8e329c
Fix matrix typing
rajsite Mar 20, 2024
d178509
lint
rajsite Mar 20, 2024
de27277
Split permutations from createMatrix
rajsite Mar 20, 2024
719ec90
Add createMatrixFromStates
rajsite Mar 20, 2024
2962347
Fix permute return strictness
rajsite Mar 20, 2024
6fdde22
interactionsWrapper initial prototype
rajsite Mar 21, 2024
87db133
lint
rajsite Mar 21, 2024
c52471c
Rename to cartesian product
rajsite Mar 21, 2024
0fd87eb
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
rajsite Mar 26, 2024
e949d6e
Add createMatrixInteractionsfromStates
rajsite Mar 26, 2024
0015819
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
rajsite Mar 26, 2024
03c7464
Clean-up merge
rajsite Mar 26, 2024
2c362ed
lint
rajsite Mar 26, 2024
5ef3097
Make open menu-button first dimension
rajsite Mar 26, 2024
8c551fd
Use shared partVisibility reference
rajsite Mar 26, 2024
46caa93
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
rajsite Mar 27, 2024
bef9528
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
rajsite Mar 27, 2024
3d8ec4c
lockfile update
rajsite Mar 27, 2024
37adef5
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
m-akinc Mar 27, 2024
ab25cc3
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
rajsite Mar 27, 2024
401dbc2
Remove unnecessary whitespace change
rajsite Mar 27, 2024
3429e9c
Minor changes
m-akinc Mar 27, 2024
87be054
Merge branch 'users/makinc/storybook-pseudo-states-2' of https://gith…
m-akinc Mar 27, 2024
e277a9f
Fix capitalization error in createMatrixInteractionsfromStates
m-akinc Mar 27, 2024
30f16c3
Merge branch 'main' into users/makinc/storybook-pseudo-states-2
m-akinc Mar 27, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
"type": "none",
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
"comment": "Add interaction stories for buttons, number field, and anchor",
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
"packageName": "@ni/nimble-components",
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
"email": "7282195+m-akinc@users.noreply.github.com",
"dependentChangeType": "none"
}
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/nimble-components/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const addons = [
}
},
'@storybook/addon-a11y',
'@storybook/addon-interactions'
'@storybook/addon-interactions',
'storybook-addon-pseudo-states'
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
];
export function webpackFinal(config) {
config.module.rules.push({
Expand Down
1 change: 1 addition & 0 deletions packages/nimble-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"rollup-plugin-sourcemaps": "^0.6.3",
"source-map-loader": "^5.0.0",
"storybook": "^7.6.13",
"storybook-addon-pseudo-states": "^2.2.1",
"ts-loader": "^9.2.5",
"typescript": "~4.8.2",
"webpack": "^5.75.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
sharedMatrixParameters,
createMatrixThemeStory
} from '../../utilities/tests/matrix';
import { disabledStates, DisabledState } from '../../utilities/tests/states';
import {
disabledStates,
DisabledState,
InteractionState,
interactionStates
} from '../../utilities/tests/states';
import { createStory } from '../../utilities/tests/storybook';
import { hiddenWrapper } from '../../utilities/tests/hidden';
import { textCustomizationWrapper } from '../../utilities/tests/text-customization';
Expand Down Expand Up @@ -49,33 +54,46 @@ type AppearanceVariantState = (typeof appearanceVariantStates)[number];

// prettier-ignore
const component = (
[interactionName, interaction]: InteractionState,
[disabledName, disabled]: DisabledState,
[appearanceName, appearance]: AppearanceState,
[appearanceVariantName, appearanceVariant]: AppearanceVariantState,
[iconVisible, labelVisible, endIconVisible]: PartVisibilityState,
): ViewTemplate => html`
<${anchorButtonTag}
class="${() => interaction}"
href="https://nimble.ni.dev"
appearance="${() => appearance}"
appearance-variant="${() => appearanceVariant}"
?disabled=${() => disabled}
?content-hidden=${() => !labelVisible}
style="margin-right: 8px; margin-bottom: 8px;">
${when(() => iconVisible, html`<${iconLinkTag} slot="start"></${iconLinkTag}>`)}
${() => `${appearanceVariantName} ${appearanceName} Link ${disabledName}`}
${() => `${interactionName} ${appearanceVariantName} ${appearanceName} Link ${disabledName}`}
${when(() => endIconVisible, html`<${iconArrowExpanderRightTag} slot="end"></${iconArrowExpanderRightTag}>`)}
</${anchorButtonTag}>
`;

export const anchorButtonThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(0, 1),
disabledStates,
appearanceStates,
appearanceVariantStates,
partVisibilityStates
])
);

export const anchorButtonInteractionsThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(1),
disabledStates,
appearanceStates,
appearanceVariantStates,
[[false, true, false]]
])
);

export const hiddenAnchorButton: StoryFn = createStory(
hiddenWrapper(
html`<${anchorButtonTag} hidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { textCustomizationWrapper } from '../../utilities/tests/text-customizati
import { AnchorAppearance } from '../types';
import { bodyFont } from '../../theme-provider/design-tokens';
import { anchorTag } from '..';
import {
interactionStates,
type InteractionState
} from '../../utilities/tests/states';

const metadata: Meta = {
title: 'Tests/Anchor',
Expand Down Expand Up @@ -41,20 +45,32 @@ type AppearanceState = (typeof appearanceStates)[number];

// prettier-ignore
const component = (
[interactionName, interaction]: InteractionState,
[disabledName, href]: DisabledState,
[underlineHiddenName, underlineHidden]: UnderlineHiddenState,
[appearanceName, appearance]: AppearanceState
): ViewTemplate => html`
<${anchorTag}
class="${() => interaction}"
href=${() => href}
?underline-hidden="${() => underlineHidden}"
appearance="${() => appearance}"
style="margin-right: 8px; margin-bottom: 8px;">
${() => `${underlineHiddenName} ${appearanceName} ${disabledName} Link`}</${anchorTag}>
${() => `${interactionName} ${underlineHiddenName} ${appearanceName} ${disabledName} Link`}</${anchorTag}>
`;

export const anchorThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(0, 1),
disabledStates,
underlineHiddenStates,
appearanceStates
])
);

export const anchorInteractionsThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(1),
disabledStates,
underlineHiddenStates,
appearanceStates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
sharedMatrixParameters,
createMatrixThemeStory
} from '../../utilities/tests/matrix';
import { disabledStates, DisabledState } from '../../utilities/tests/states';
import {
disabledStates,
DisabledState,
InteractionState,
interactionStates
} from '../../utilities/tests/states';
import { createStory } from '../../utilities/tests/storybook';
import { hiddenWrapper } from '../../utilities/tests/hidden';
import { textCustomizationWrapper } from '../../utilities/tests/text-customization';
Expand Down Expand Up @@ -47,32 +52,45 @@ type AppearanceVariantState = (typeof appearanceVariantStates)[number];

// prettier-ignore
const component = (
[interactionName, interaction]: InteractionState,
[disabledName, disabled]: DisabledState,
[appearanceName, appearance]: AppearanceState,
[appearanceVariantName, appearanceVariant]: AppearanceVariantState,
[iconVisible, labelVisible, endIconVisible]: PartVisibilityState,
): ViewTemplate => html`
<${buttonTag}
class="${() => interaction}"
appearance="${() => appearance}"
appearance-variant="${() => appearanceVariant}"
?disabled=${() => disabled}
?content-hidden=${() => !labelVisible}
style="margin-right: 8px; margin-bottom: 8px;">
${when(() => iconVisible, html`<${iconKeyTag} slot="start"></${iconKeyTag}>`)}
${() => `${appearanceVariantName} ${appearanceName} Button ${disabledName}`}
${() => `${interactionName} ${appearanceVariantName} ${appearanceName} Button ${disabledName}`}
${when(() => endIconVisible, html`<${iconArrowExpanderDownTag} slot="end"></${iconArrowExpanderDownTag}>`)}
</${buttonTag}>
`;

export const buttonThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(0, 1),
disabledStates,
appearanceStates,
appearanceVariantStates,
partVisibilityStates
])
);

export const buttonInteractionsThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(1),
disabledStates,
appearanceStates,
appearanceVariantStates,
[[false, true, false]]
])
);

export const hiddenButton: StoryFn = createStory(
hiddenWrapper(html`<${buttonTag} hidden>Hidden Button</${buttonTag}>`)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import {
sharedMatrixParameters,
createMatrixThemeStory
} from '../../utilities/tests/matrix';
import { disabledStates, DisabledState } from '../../utilities/tests/states';
import {
disabledStates,
DisabledState,
InteractionState,
interactionStates
} from '../../utilities/tests/states';
import { createStory } from '../../utilities/tests/storybook';
import { hiddenWrapper } from '../../utilities/tests/hidden';
import { iconArrowExpanderDownTag } from '../../icons/arrow-expander-down';
import { iconKeyTag } from '../../icons/key';
import { menuButtonTag } from '..';
import { menuTag } from '../../menu';
import { menuItemTag } from '../../menu-item';

const metadata: Meta = {
title: 'Tests/Menu Button',
Expand All @@ -35,36 +38,53 @@ const partVisibilityStates = [
] as const;
type PartVisibilityState = (typeof partVisibilityStates)[number];

const openStates = [
['', false],
['Open', true]
] as const;
type OpenState = (typeof openStates)[number];

const appearanceStates = Object.entries(ButtonAppearance).map(
([key, value]) => [pascalCase(key), value]
);
type AppearanceState = (typeof appearanceStates)[number];

// prettier-ignore
const component = (
[interactionName, interaction]: InteractionState,
[iconVisible, labelVisible, endIconVisible]: PartVisibilityState,
[openName, open]: OpenState,
[disabledName, disabled]: DisabledState,
[appearanceName, appearance]: AppearanceState
): ViewTemplate => html`
<${menuButtonTag}
class="${() => interaction}"
appearance="${() => appearance}"
?open="${() => open}"
?disabled=${() => disabled}
?content-hidden=${() => !labelVisible}
style="margin-right: 8px; margin-bottom: 8px;">
${when(() => iconVisible, html`<${iconKeyTag} slot="start"></${iconKeyTag}>`)}
${() => `${appearanceName!} Menu Button ${disabledName}`}
${() => `${interactionName} ${openName} ${appearanceName!} Menu Button ${disabledName}`}
${when(() => endIconVisible, html`<${iconArrowExpanderDownTag} slot="end"></${iconArrowExpanderDownTag}>`)}

<${menuTag} slot="menu">
<${menuItemTag}>Item 1</${menuItemTag}>
<${menuItemTag}>Item 2</${menuItemTag}>
</${menuTag}>
</${menuButtonTag}>
`;

export const menuButtonThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(0, 1),
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
partVisibilityStates,
openStates,
disabledStates,
appearanceStates
])
);

export const menuButtonInteractionsThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(1),
[[false, true, false]],
openStates,
disabledStates,
appearanceStates
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
disabledStates,
DisabledState,
errorStates,
ErrorState
ErrorState,
InteractionState,
interactionStates
} from '../../utilities/tests/states';
import { hiddenWrapper } from '../../utilities/tests/hidden';
import { NumberFieldAppearance } from '../types';
Expand Down Expand Up @@ -44,6 +46,7 @@ const hideStepStates = [
type HideStepState = (typeof hideStepStates)[number];

const component = (
[interactionName, interaction]: InteractionState,
[disabledName, disabled]: DisabledState,
[hideStepName, hideStep]: HideStepState,
[valueName, valueValue, placeholderValue]: ValueState,
Expand All @@ -52,7 +55,7 @@ const component = (
): ViewTemplate => html`
<${numberFieldTag}
style="width: 250px; padding: 8px;"
class="${() => errorVisible}"
class="${() => errorVisible} ${() => interaction}"
value="${() => valueValue}"
placeholder="${() => placeholderValue}"
appearance="${() => appearance}"
Expand All @@ -61,13 +64,14 @@ const component = (
error-text="${() => errorText}"
?error-visible="${() => errorVisible}"
>
${() => errorName} ${() => appearanceName} ${() => valueName}
${interactionName} ${() => errorName} ${() => appearanceName} ${() => valueName}
${() => hideStepName} ${() => disabledName}
</${numberFieldTag}>
`;

export const numberFieldThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.slice(0, 1),
disabledStates,
hideStepStates,
valueStates,
Expand All @@ -76,6 +80,17 @@ export const numberFieldThemeMatrix: StoryFn = createMatrixThemeStory(
])
);

export const numberFieldInteractionsThemeMatrix: StoryFn = createMatrixThemeStory(
createMatrix(component, [
interactionStates.filter(x => x[0] && !x[0].includes('Active')),
disabledStates,
hideStepStates.slice(0, 1),
valueStates.slice(1, 2),
errorStates.slice(0, 2),
m-akinc marked this conversation as resolved.
Show resolved Hide resolved
appearanceStates
])
);

export const hiddenNumberField: StoryFn = createStory(
hiddenWrapper(
html`
Expand Down
Loading
Loading