@kaizen/components 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/codemods/migrateGuidanceBlockActionsToActionsSlot/migrateGuidanceBlockActionsToActionsSlot.spec.ts +209 -26
  2. package/codemods/migrateGuidanceBlockActionsToActionsSlot/migrateGuidanceBlockActionsToActionsSlot.ts +24 -1
  3. package/codemods/migrateGuidanceBlockActionsToActionsSlot/transformActionsToActionsSlot.spec.ts +107 -1
  4. package/codemods/migrateGuidanceBlockActionsToActionsSlot/transformActionsToActionsSlot.ts +20 -0
  5. package/codemods/runV1Codemods/__snapshots__/runV1Codemods.spec.ts.snap +2 -3
  6. package/codemods/runV1Codemods/runV1Codemods.spec.ts +2 -3
  7. package/codemods/utils/transformV1ButtonPropsToButtonOrLinkButton.ts +44 -14
  8. package/dist/cjs/src/MenuV1/index.cjs +4 -3
  9. package/dist/cjs/src/TitleBlock/TitleBlock.cjs +26 -36
  10. package/dist/cjs/src/TitleBlock/TitleBlock.module.scss.cjs +3 -0
  11. package/dist/cjs/src/TitleBlock/subcomponents/MainActions.cjs +90 -45
  12. package/dist/cjs/src/TitleBlock/subcomponents/MainActions.module.scss.cjs +3 -1
  13. package/dist/cjs/src/TitleBlock/subcomponents/SecondaryActions.cjs +51 -14
  14. package/dist/esm/src/MenuV1/index.mjs +5 -3
  15. package/dist/esm/src/TitleBlock/TitleBlock.mjs +27 -37
  16. package/dist/esm/src/TitleBlock/TitleBlock.module.scss.mjs +3 -0
  17. package/dist/esm/src/TitleBlock/subcomponents/MainActions.mjs +92 -47
  18. package/dist/esm/src/TitleBlock/subcomponents/MainActions.module.scss.mjs +3 -1
  19. package/dist/esm/src/TitleBlock/subcomponents/SecondaryActions.mjs +51 -14
  20. package/dist/styles.css +51 -201
  21. package/dist/types/TitleBlock/TitleBlock.d.ts +1 -1
  22. package/dist/types/TitleBlock/subcomponents/MainActions.d.ts +4 -3
  23. package/package.json +1 -1
  24. package/src/TitleBlock/TitleBlock.module.scss +28 -10
  25. package/src/TitleBlock/TitleBlock.spec.tsx +33 -461
  26. package/src/TitleBlock/TitleBlock.tsx +4 -24
  27. package/src/TitleBlock/_docs/TitleBlock.stories.tsx +25 -5
  28. package/src/TitleBlock/_mixins.scss +6 -0
  29. package/src/TitleBlock/subcomponents/MainActions.module.scss +27 -2
  30. package/src/TitleBlock/subcomponents/MainActions.tsx +127 -70
  31. package/src/TitleBlock/subcomponents/SecondaryActions.tsx +105 -45
  32. package/src/TitleBlock/subcomponents/Toolbar.tsx +1 -0
  33. package/dist/cjs/src/MenuV1/subcomponents/MenuHeading/MenuHeading.cjs +0 -27
  34. package/dist/cjs/src/MenuV1/subcomponents/MenuHeading/MenuHeading.module.scss.cjs +0 -6
  35. package/dist/cjs/src/TitleBlock/subcomponents/MobileActions.cjs +0 -306
  36. package/dist/cjs/src/TitleBlock/subcomponents/MobileActions.module.scss.cjs +0 -16
  37. package/dist/esm/src/MenuV1/subcomponents/MenuHeading/MenuHeading.mjs +0 -21
  38. package/dist/esm/src/MenuV1/subcomponents/MenuHeading/MenuHeading.module.scss.mjs +0 -4
  39. package/dist/esm/src/TitleBlock/subcomponents/MobileActions.mjs +0 -300
  40. package/dist/esm/src/TitleBlock/subcomponents/MobileActions.module.scss.mjs +0 -14
  41. package/dist/types/TitleBlock/subcomponents/MobileActions.d.ts +0 -14
  42. package/src/TitleBlock/subcomponents/MobileActions.module.scss +0 -208
  43. package/src/TitleBlock/subcomponents/MobileActions.spec.tsx +0 -210
  44. package/src/TitleBlock/subcomponents/MobileActions.tsx +0 -472
@@ -1,14 +0,0 @@
1
- import type { ButtonProps } from "../../Button";
2
- import { type DefaultActionProps, type PrimaryActionProps, type SecondaryActionsProps, type TitleBlockMenuItemProps } from '../types';
3
- export type MobileActionsProps = {
4
- primaryAction?: PrimaryActionProps;
5
- defaultAction?: DefaultActionProps;
6
- secondaryActions?: SecondaryActionsProps;
7
- secondaryOverflowMenuItems?: TitleBlockMenuItemProps[];
8
- drawerHandleLabelIconPosition?: ButtonProps['iconPosition'];
9
- autoHide?: boolean;
10
- };
11
- export declare const MobileActions: {
12
- ({ primaryAction, defaultAction, secondaryActions, secondaryOverflowMenuItems, drawerHandleLabelIconPosition, autoHide, }: MobileActionsProps): JSX.Element;
13
- displayName: string;
14
- };
@@ -1,208 +0,0 @@
1
- @import '~@kaizen/design-tokens/sass/spacing';
2
- @import '~@kaizen/design-tokens/sass/typography';
3
- @import '~@kaizen/design-tokens/sass/color';
4
- @import '~@kaizen/design-tokens/sass/layout';
5
- @import '~@kaizen/design-tokens/sass/border';
6
- @import '../../../styles/utils/legacy/layout';
7
- @import '../../../styles/utils/legacy/grid';
8
- @import '../../../styles/utils/layers';
9
- @import '../mixins';
10
-
11
- @layer kz-components {
12
- $expand-button-width: 3.75rem;
13
- $focus-spacing: 2px;
14
- $focus-ring-border-width: 2px; // should be $border-focus-ring-border-width but CSS vars makes this hard
15
- $space-for-focus-ring: ($focus-ring-border-width * 2) + ($focus-spacing * 2);
16
- $slide-up-duration: 0.4s;
17
-
18
- /* stylelint-disable no-descending-specificity */
19
- .mobileActionsContainer {
20
- display: none;
21
- z-index: $ca-z-index-fixed;
22
- flex-direction: column;
23
- position: fixed;
24
- bottom: 0;
25
- left: 0;
26
- right: 0;
27
- border-start-start-radius: $border-solid-border-radius;
28
- border-start-end-radius: $border-solid-border-radius;
29
- -webkit-font-smoothing: antialiased;
30
- -moz-osx-font-smoothing: grayscale;
31
- overflow: hidden;
32
- transform: translateY(calc(100% - #{$layout-mobile-actions-drawer-height}));
33
- transition: $slide-up-duration ease;
34
- animation: slide-up 1s ease;
35
-
36
- &.isOpen {
37
- transform: translateY(0%);
38
-
39
- .mobileActionsMenuContainer {
40
- visibility: visible;
41
- }
42
- }
43
-
44
- @include title-block-small {
45
- display: flex;
46
- }
47
- }
48
-
49
- .mobileActionsTopRow {
50
- display: flex;
51
- align-items: center;
52
- justify-content: space-between;
53
- height: $layout-mobile-actions-drawer-height;
54
- }
55
-
56
- .mobileActionsTopRow.mobileActionsTopRowSingleButton {
57
- justify-content: center;
58
- }
59
-
60
- .mobileActionsMenuContainer {
61
- visibility: hidden;
62
- width: 100%;
63
- background: $color-white;
64
- padding: $spacing-xs 0;
65
- transition: visibility $slide-up-duration;
66
- }
67
-
68
- .drawerHandleIcon {
69
- display: flex;
70
- justify-content: center;
71
- align-items: center;
72
-
73
- @include ca-margin($end: calc(#{$ca-grid} / 2));
74
-
75
- .drawerHandleLabelText + & {
76
- @include ca-margin($start: calc(#{$ca-grid} / 2));
77
- }
78
- }
79
-
80
- .mobileActionsPrimaryLabel {
81
- text-align: left;
82
- text-decoration: none;
83
- color: $color-white;
84
- font-family: $typography-button-primary-font-family;
85
- font-weight: $typography-button-primary-font-weight;
86
- font-size: $typography-button-primary-font-size;
87
- line-height: $typography-button-primary-line-height;
88
- letter-spacing: $typography-button-primary-letter-spacing;
89
-
90
- @include ca-padding($start: $ca-grid * 0.75);
91
- }
92
-
93
- .mobileActionsPrimaryButton,
94
- .mobileActionsExpandButton {
95
- display: flex;
96
- position: relative;
97
- justify-content: flex-start;
98
- align-items: center;
99
- height: 100%;
100
- border: 0;
101
- box-sizing: border-box;
102
- color: $color-white;
103
- background-color: $color-blue-500;
104
-
105
- &:focus {
106
- background-color: $color-blue-600;
107
- outline: none;
108
- }
109
-
110
- &:focus-visible {
111
- height: $layout-mobile-actions-drawer-height - $space-for-focus-ring;
112
-
113
- &::after {
114
- $focus-ring-offset: calc((#{$border-focus-ring-border-width} * 2));
115
-
116
- content: '';
117
- position: absolute;
118
- background: transparent;
119
- border-width: $focus-ring-border-width;
120
- border-style: $border-focus-ring-border-style;
121
- border-color: $color-blue-500;
122
- inset: calc(-1 * #{$focus-ring-offset});
123
- }
124
- }
125
-
126
- &:hover {
127
- text-decoration: none;
128
- }
129
- }
130
-
131
- // Full width versions
132
- .mobileActionsPrimaryButton:only-child,
133
- .mobileActionsExpandButton:only-child {
134
- flex-basis: 100%;
135
- border-start-start-radius: $border-solid-border-radius;
136
- border-start-end-radius: $border-solid-border-radius;
137
-
138
- &:focus-visible {
139
- flex-basis: calc(100% - #{$space-for-focus-ring});
140
-
141
- &::after {
142
- border-start-start-radius: $border-focus-ring-border-radius;
143
- border-start-end-radius: $border-focus-ring-border-radius;
144
- }
145
- }
146
- }
147
-
148
- // Non full width versions
149
- .mobileActionsPrimaryButton:not(:only-child) {
150
- flex: 0 0 calc(100% - #{$expand-button-width});
151
-
152
- &:focus-visible {
153
- flex-basis: calc(100% - #{$expand-button-width} - #{$space-for-focus-ring});
154
- margin-left: $focus-ring-border-width * 2;
155
- border-start-start-radius: $border-solid-border-radius;
156
-
157
- & + .mobileActionsExpandButton {
158
- border-color: $color-white;
159
- }
160
-
161
- &::after {
162
- border-start-start-radius: $border-focus-ring-border-radius;
163
- }
164
- }
165
- }
166
-
167
- .mobileActionsExpandButton:not(:only-child) {
168
- flex: 0 0 $expand-button-width;
169
- border-left: 2px solid $color-blue-200;
170
- justify-content: center;
171
-
172
- &:focus-visible {
173
- border-color: $color-white;
174
- flex-basis: calc(#{$expand-button-width} - #{$space-for-focus-ring});
175
- margin-right: $focus-ring-border-width * 2;
176
- border-start-end-radius: $border-solid-border-radius;
177
-
178
- &::after {
179
- border-start-end-radius: $border-focus-ring-border-radius;
180
- }
181
- }
182
- }
183
-
184
- .mobileActionsChevronSquare {
185
- display: flex;
186
- justify-content: center;
187
- align-items: center;
188
- height: 100%;
189
- position: absolute;
190
-
191
- @include ca-position($end: 20px);
192
- }
193
- /* stylelint-enable no-descending-specificity */
194
- }
195
-
196
- @keyframes slide-up {
197
- 0% {
198
- transform: translateY(100%);
199
- }
200
-
201
- 50% {
202
- transform: translateY(100%);
203
- }
204
-
205
- 100% {
206
- transform: translateY(calc(100% - #{$layout-mobile-actions-drawer-height}));
207
- }
208
- }
@@ -1,210 +0,0 @@
1
- import React from 'react'
2
- import { render, screen, waitFor } from '@testing-library/react'
3
- import userEvent from '@testing-library/user-event'
4
- import { vi } from 'vitest'
5
- import { MobileActions } from './MobileActions'
6
- const user = userEvent.setup()
7
-
8
- const MENU_LINKS = [
9
- {
10
- label: 'Primary menu link 1',
11
- href: '#',
12
- },
13
- {
14
- label: 'Primary menu action 2',
15
- onClick: (): void => alert('test'),
16
- },
17
- ]
18
-
19
- const SECONDARY_ACTIONS = [
20
- {
21
- label: 'Secondary menu',
22
- menuItems: [
23
- {
24
- onClick: (): void => alert('test'),
25
- label: 'Secondary menu action 1',
26
- },
27
- {
28
- onClick: (): void => alert('test'),
29
- label: 'Secondary menu action 2',
30
- },
31
- ],
32
- },
33
- {
34
- onClick: (): void => alert('test'),
35
- label: 'Secondary action',
36
- },
37
- ]
38
-
39
- const SECONDARY_OVERFLOW_ACTIONS = [
40
- {
41
- onClick: (): void => alert('test'),
42
- label: 'Secondary overflow action',
43
- },
44
- ]
45
-
46
- describe('<MobileActions />', () => {
47
- describe('Case 1: Primary Action is a menu', () => {
48
- it('makes aria-expanded toggles between true and false when user toggles the menu', async () => {
49
- render(
50
- <MobileActions
51
- primaryAction={{
52
- label: 'Primary menu',
53
- menuItems: MENU_LINKS,
54
- }}
55
- defaultAction={{
56
- label: 'Default link',
57
- href: '#',
58
- }}
59
- secondaryActions={SECONDARY_ACTIONS}
60
- />,
61
- )
62
- const mobileActionsButton = screen.getByRole('button', {
63
- name: 'Primary menu',
64
- })
65
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
66
-
67
- await user.click(mobileActionsButton)
68
- await waitFor(() => {
69
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('true')
70
- })
71
- await user.click(mobileActionsButton)
72
- await waitFor(() => {
73
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
74
- })
75
- })
76
- })
77
-
78
- describe('Primary Action does not have a menu list', () => {
79
- it('makes aria-expanded toggles between true and false when user toggles the menu', async () => {
80
- render(
81
- <MobileActions
82
- primaryAction={{
83
- label: 'Primary menu',
84
- }}
85
- defaultAction={{
86
- label: 'Default link',
87
- href: '#',
88
- }}
89
- secondaryActions={SECONDARY_ACTIONS}
90
- />,
91
- )
92
- const mobileActionsButton = screen.getByRole('button', {
93
- name: 'Other actions',
94
- })
95
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
96
-
97
- await user.click(mobileActionsButton)
98
- await waitFor(() => {
99
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('true')
100
- })
101
- await user.click(mobileActionsButton)
102
- await waitFor(() => {
103
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
104
- })
105
- })
106
- })
107
-
108
- describe('No primary actions', () => {
109
- it('makes aria-expanded toggles between true and false when user toggles the menu', async () => {
110
- render(
111
- <MobileActions
112
- defaultAction={{
113
- label: 'Default link',
114
- href: '#',
115
- }}
116
- secondaryActions={SECONDARY_ACTIONS}
117
- />,
118
- )
119
- const mobileActionsButton = screen.getByRole('button', {
120
- name: 'Other actions',
121
- })
122
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
123
-
124
- await user.click(mobileActionsButton)
125
- await waitFor(() => {
126
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('true')
127
- })
128
- await user.click(mobileActionsButton)
129
- await waitFor(() => {
130
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
131
- })
132
- })
133
- })
134
- })
135
-
136
- describe('when autoHide is true', () => {
137
- beforeEach(() => {
138
- window.alert = vi.fn()
139
- render(
140
- <MobileActions
141
- primaryAction={{
142
- label: 'Primary menu',
143
- }}
144
- defaultAction={{
145
- label: 'Default link',
146
- href: '#',
147
- }}
148
- secondaryActions={SECONDARY_ACTIONS}
149
- secondaryOverflowMenuItems={SECONDARY_OVERFLOW_ACTIONS}
150
- autoHide
151
- />,
152
- )
153
- })
154
- it('hides the menu when user clicks a default action item', async () => {
155
- const mobileActionsButton = screen.getByRole('button', {
156
- name: 'Other actions',
157
- })
158
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
159
-
160
- await user.click(mobileActionsButton)
161
- await waitFor(() => {
162
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('true')
163
- })
164
- const btn = screen.getAllByTestId(/title-block-mobile-actions-default-/)
165
- expect(btn.length).toEqual(1)
166
- await user.click(btn[0])
167
-
168
- await waitFor(() => {
169
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
170
- })
171
- })
172
-
173
- it('hides the menu when user clicks a secondary action item', async () => {
174
- const mobileActionsButton = screen.getByRole('button', {
175
- name: 'Other actions',
176
- })
177
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
178
-
179
- await user.click(mobileActionsButton)
180
- await waitFor(() => {
181
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('true')
182
- })
183
- const btn = screen.getAllByTestId('title-block-mobile-actions-secondary-action')
184
- expect(btn.length).toEqual(3)
185
- await user.click(btn[0])
186
-
187
- await waitFor(() => {
188
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
189
- })
190
- })
191
-
192
- it('hides the menu when user clicks a secondary overflow item', async () => {
193
- const mobileActionsButton = screen.getByRole('button', {
194
- name: 'Other actions',
195
- })
196
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
197
-
198
- await user.click(mobileActionsButton)
199
- await waitFor(() => {
200
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('true')
201
- })
202
- const btn = screen.getAllByTestId('title-block-mobile-actions-overflow-menu-item')
203
- expect(btn.length).toEqual(1)
204
- await user.click(btn[0])
205
-
206
- await waitFor(() => {
207
- expect(mobileActionsButton.getAttribute('aria-expanded')).toEqual('false')
208
- })
209
- })
210
- })