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

feat(action-menu): added static attribute support #3573

Merged
merged 14 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 4 additions & 0 deletions packages/action-menu/src/ActionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class ActionMenu extends ObserveSlotText(PickerBase, 'label') {
@property({ type: String })
public override selects: undefined | 'single' = undefined;

@property({ type: String, reflect: true })
public static: 'white' | 'black' | undefined = undefined;
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved

protected override listRole: 'listbox' | 'menu' = 'menu';
protected override itemRole = 'menuitem';
private get hasLabel(): boolean {
Expand All @@ -66,6 +69,7 @@ export class ActionMenu extends ObserveSlotText(PickerBase, 'label') {
<sp-action-button
?quiet=${this.quiet}
?selected=${this.open}
static=${ifDefined(this.static || undefined)}
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved
aria-haspopup="true"
aria-controls=${ifDefined(this.open ? 'menu' : undefined)}
aria-expanded=${this.open ? 'true' : 'false'}
Expand Down
29 changes: 29 additions & 0 deletions packages/action-menu/stories/action-menu.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import '@spectrum-web-components/menu/sp-menu-group.js';
import '@spectrum-web-components/menu/sp-menu-divider.js';
import '@spectrum-web-components/tooltip/sp-tooltip.js';
import { ActionMenuMarkup } from './';
import { makeOverBackground } from '../../button/stories/index.js';

import '@spectrum-web-components/icons-workflow/icons/sp-icon-settings.js';
import type { MenuItem } from '@spectrum-web-components/menu/src/MenuItem.js';

export default {
component: 'sp-action-menu',
title: 'Action menu',
decorators: [makeOverBackground()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
decorators: [makeOverBackground()],

argTypes: {
disabled: {
name: 'disabled',
Expand Down Expand Up @@ -112,6 +114,19 @@ export default {
type: 'boolean',
},
},
staticValue: {
name: 'static',
type: { name: 'string', required: false },
description: 'The visual static variant to apply to the button.',
table: {
type: { summary: 'string' },
defaultValue: { summary: undefined },
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved
},
control: {
type: 'select',
options: ['white', 'black', undefined],
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
args: {
visibleLabel: 'More Actions',
Expand All @@ -120,6 +135,7 @@ export default {
quiet: false,
tooltipDescription: '',
tooltipPlacement: 'bottom',
static: undefined,
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved
},
};

Expand All @@ -131,6 +147,7 @@ interface StoryArgs {
selects?: 'single';
selected?: boolean;
quiet?: boolean;
stati?: 'white' | 'black';
tooltipDescription?: string | 'none';
tooltipPlacement?: string | 'none';
}
Expand All @@ -140,6 +157,18 @@ const Template = (args: StoryArgs = {}): TemplateResult =>

export const Default = (args: StoryArgs = {}): TemplateResult => Template(args);

export const staticWhite = (args: StoryArgs = {}): TemplateResult =>
Template(args);
staticWhite.args = {
staticValue: 'white',
};
Rajdeepc marked this conversation as resolved.
Show resolved Hide resolved

export const staticBlack = (args: StoryArgs = {}): TemplateResult =>
Template(args);
staticBlack.args = {
staticValue: 'black',
};

export const quiet = (args: StoryArgs = {}): TemplateResult => Template(args);
quiet.args = {
quiet: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/action-menu/stories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import { html, TemplateResult } from '@spectrum-web-components/base';

import '@spectrum-web-components/action-menu/sp-action-menu.js';
Expand All @@ -23,6 +24,7 @@ export const ActionMenuMarkup = ({
disabled = false,
open = false,
quiet = false,
staticValue = '',
visibleLabel = '',
customIcon = '' as string | TemplateResult,
size = 'm' as 'm' | 's' | 'l' | 'xl' | 'xxl',
Expand All @@ -37,6 +39,7 @@ export const ActionMenuMarkup = ({
?disabled=${disabled}
?open=${open}
?quiet=${quiet}
static=${staticValue}
size=${size}
@change="${changeHandler}"
.selects=${selects ? selects : undefined}
Expand Down
15 changes: 15 additions & 0 deletions packages/action-menu/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ export const testActionMenu = (mode: 'sync' | 'async'): void => {

expect(el.quiet).to.be.true;
});
it('can be `static`', async () => {
const el = await actionMenuFixture();

expect(el.static == undefined).to.be.true;

el.static = 'black';
await elementUpdated(el);

expect(el.static == 'black').to.be.true;

el.static = 'white';
await elementUpdated(el);

expect(el.static == 'white').to.be.true;
});
it('stay `valid`', async () => {
const el = await actionMenuFixture();

Expand Down