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

Rich text editor | Nimble listbox component bring up for mention popup #1654

Merged
merged 10 commits into from
Nov 11, 2023
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Nimble list box component bring up",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
26 changes: 26 additions & 0 deletions packages/nimble-components/src/listbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
DesignSystem,
ListboxElement as FoundationListbox,
listboxTemplate as template
} from '@microsoft/fast-foundation';
import { styles } from './styles';

declare global {
interface HTMLElementTagNameMap {
'nimble-listbox': Listbox;
}
}

/**
* A nimble-styled HTML list box
*/
export class Listbox extends FoundationListbox {}

const nimbleListbox = Listbox.compose({
baseName: 'listbox',
template,
styles
});

DesignSystem.getOrCreate().withPrefix('nimble').register(nimbleListbox());
export const listboxTag = DesignSystem.tagFor(Listbox);
35 changes: 35 additions & 0 deletions packages/nimble-components/src/listbox/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { css } from '@microsoft/fast-element';
import { display } from '@microsoft/fast-foundation';

import {
applicationBackgroundColor,
borderWidth,
popupBorderColor,
elevation2BoxShadow,
bodyFont,
bodyFontColor
} from '../theme-provider/design-tokens';

export const styles = css`
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
${display('grid')}

:host {
background: ${applicationBackgroundColor};
border: ${borderWidth} solid ${popupBorderColor};
margin: 0;
min-width: 176px;
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
width: max-content;
box-shadow: ${elevation2BoxShadow};
color: ${bodyFontColor};
font: ${bodyFont};
}

:host(:focus) {
outline: 0px;
}

slot {
padding: 4px;
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
display: block;
}
`;
13 changes: 13 additions & 0 deletions packages/nimble-components/src/listbox/tests/listbox.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Listbox, listboxTag } from '..';

describe('Listbox', () => {
it('should export its tag', () => {
expect(listboxTag).toBe('nimble-listbox');
});

it('can construct an element instance', () => {
expect(document.createElement('nimble-listbox')).toBeInstanceOf(
Listbox
);
});
});
33 changes: 33 additions & 0 deletions packages/nimble-components/src/listbox/tests/listbox.stories.ts
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { html } from '@microsoft/fast-element';
import type { Meta, StoryObj } from '@storybook/html';
import { createUserSelectedThemeStory } from '../../utilities/tests/storybook';
import { listboxTag } from '..';
import { listOptionTag } from '../../list-option';

const listboxDescription = 'Per [W3C](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/) - A listbox widget presents a list of options and allows a user to select one or more of them. A listbox that allows a single option to be chosen is a single-select listbox; one that allows multiple options to be selected is a multi-select listbox.';

const metadata: Meta = {
title: 'Tests/Listbox',
tags: ['autodocs'],
parameters: {
docs: {
description: {
component: listboxDescription
}
}
},
// prettier-ignore
render: createUserSelectedThemeStory(html`
<${listboxTag}>
<${listOptionTag} value="1">Option 1</${listOptionTag}>
<${listOptionTag} value="2">Option 2</${listOptionTag}>
<${listOptionTag} value="3">Option 3</${listOptionTag}>
<${listOptionTag} value="4">Option 4</${listOptionTag}>
<${listOptionTag} value="5">Option 5</${listOptionTag}>
</${listboxTag}>
`)
};

export default metadata;

export const listbox: StoryObj = {};
vivinkrishna-ni marked this conversation as resolved.
Show resolved Hide resolved
Loading