-
Notifications
You must be signed in to change notification settings - Fork 39
refactor(atomic): migrate atomic-tab to Lit #6603
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3b9b139
Initial plan
Copilot 8de4bd9
Changes before error encountered
Copilot 62d5904
feat(atomic): add unit tests for atomic-tab component
Copilot f7dce3e
feat(atomic): complete atomic-tab migration to Lit with documentation
Copilot 30a950a
proper
alexprudhomme 14301a2
Update packages/atomic/src/components/search/atomic-tab/atomic-tab.ts
alexprudhomme c214ed9
Update atomic-tab.mdx
alexprudhomme 2be1862
Merge branch 'copilot/migrate-atomic-tab' of https://github.com/coveoβ¦
alexprudhomme 1d9a343
Update atomic-tab.new.stories.tsx
alexprudhomme a3d5a8d
Merge branch 'main' into copilot/migrate-atomic-tab
alexprudhomme b585d07
Add generated files
developer-experience-bot[bot] 39c0b63
Update tab-button.tsx
alexprudhomme 3e1863d
Merge branch 'copilot/migrate-atomic-tab' of https://github.com/coveoβ¦
alexprudhomme dba16bb
Merge branch 'main' into copilot/migrate-atomic-tab
alexprudhomme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/atomic/src/components/search/atomic-tab/atomic-tab.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { Meta } from '@storybook/addon-docs/blocks'; | ||
| import * as AtomicTabStories from './atomic-tab.new.stories'; | ||
| import { AtomicDocTemplate } from '../../../../storybook-utils/documentation/atomic-doc-template'; | ||
|
|
||
|
|
||
| <Meta of={AtomicTabStories} /> | ||
|
|
||
| <AtomicDocTemplate | ||
| stories={AtomicTabStories} | ||
| githubPath="search/atomic-tab/atomic-tab.ts" | ||
| tagName="atomic-tab" | ||
| className="AtomicTab" | ||
| > | ||
|
|
||
| The `atomic-tab` component represents an individual tab within the `atomic-tab-manager` component. | ||
| It must be used as a child of the `atomic-tab-manager` component to function correctly. | ||
|
|
||
| This component is not used standalone. It must be a child of `atomic-tab-manager`. | ||
|
|
||
| See the [atomic-tab-manager documentation](?path=/docs/atomic-tab-manager--docs) for additional usage examples. | ||
|
|
||
| ```html | ||
| <atomic-search-interface> | ||
| <!-- other components --> | ||
|
|
||
| <atomic-tab-manager> | ||
| <atomic-tab name="all" label="All"></atomic-tab> | ||
| <atomic-tab name="images" label="Images" expression="@objecttype==Image"></atomic-tab> | ||
| <atomic-tab name="articles" label="Articles" expression="@objecttype==Article"></atomic-tab> | ||
| </atomic-tab-manager> | ||
|
|
||
| <!-- other components --> | ||
| </atomic-search-interface> | ||
| ``` | ||
|
|
||
| ## Related Components | ||
|
|
||
| - [atomic-tab-manager](?path=/docs/atomic-tab-manager--docs): Manages a collection of tabs and allows users to switch between them | ||
|
|
||
| </AtomicDocTemplate> | ||
44 changes: 44 additions & 0 deletions
44
packages/atomic/src/components/search/atomic-tab/atomic-tab.new.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type {Meta, StoryObj as Story} from '@storybook/web-components-vite'; | ||
| import {getStorybookHelpers} from '@wc-toolkit/storybook-helpers'; | ||
| import {html} from 'lit'; | ||
| import {parameters} from '@/storybook-utils/common/common-meta-parameters'; | ||
| import {wrapInSearchInterface} from '@/storybook-utils/search/search-interface-wrapper'; | ||
|
|
||
| const {decorator, play} = wrapInSearchInterface(); | ||
|
|
||
| const {events, argTypes} = getStorybookHelpers('atomic-tab', { | ||
| excludeCategories: ['methods'], | ||
| }); | ||
|
|
||
| const meta: Meta = { | ||
| component: 'atomic-tab', | ||
| title: 'Search/Tab/atomic-tab', | ||
| id: 'atomic-tab', | ||
| render: () => html`<atomic-tab-manager> | ||
| <atomic-tab | ||
| label="All" | ||
| name="all" | ||
| ></atomic-tab> | ||
| <atomic-tab | ||
| label="Images" | ||
| name="images" | ||
| ></atomic-tab> | ||
| <atomic-tab | ||
| label="Articles" | ||
| name="articles" | ||
| ></atomic-tab> | ||
| </atomic-tab-manager>`, | ||
| decorators: [decorator], | ||
| parameters: { | ||
| ...parameters, | ||
| actions: { | ||
| handles: events, | ||
| }, | ||
| }, | ||
| argTypes, | ||
| play, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| export const Default: Story = {}; |
86 changes: 86 additions & 0 deletions
86
packages/atomic/src/components/search/atomic-tab/atomic-tab.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import {html} from 'lit'; | ||
| import {describe, expect, it} from 'vitest'; | ||
| import {fixture} from '@/vitest-utils/testing-helpers/fixture'; | ||
| import type {AtomicTab} from './atomic-tab'; | ||
| import './atomic-tab'; | ||
|
|
||
| describe('atomic-tab', () => { | ||
| const renderTab = async ({ | ||
| label = 'Test Tab', | ||
| name = 'test-tab', | ||
| expression = '', | ||
| } = {}) => { | ||
| const element = await fixture<AtomicTab>(html` | ||
| <atomic-tab | ||
| label="${label}" | ||
| name="${name}" | ||
| expression="${expression}" | ||
| ></atomic-tab> | ||
| `); | ||
|
|
||
| return {element}; | ||
| }; | ||
|
|
||
| describe('when rendering with valid props', () => { | ||
| it('should render successfully with required props', async () => { | ||
| const {element} = await renderTab(); | ||
| expect(element).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render successfully with all props', async () => { | ||
| const {element} = await renderTab({ | ||
| label: 'My Tab', | ||
| name: 'my-tab', | ||
| expression: '@source==MySource', | ||
| }); | ||
| expect(element).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should reflect label property to attribute', async () => { | ||
| const {element} = await renderTab({label: 'Custom Label'}); | ||
| expect(element.getAttribute('label')).toBe('Custom Label'); | ||
| }); | ||
|
|
||
| it('should reflect name property to attribute', async () => { | ||
| const {element} = await renderTab({name: 'custom-name'}); | ||
| expect(element.getAttribute('name')).toBe('custom-name'); | ||
| }); | ||
|
|
||
| it('should reflect expression property to attribute', async () => { | ||
| const {element} = await renderTab({expression: '@source==Test'}); | ||
| expect(element.getAttribute('expression')).toBe('@source==Test'); | ||
| }); | ||
|
|
||
| it('should have empty expression by default', async () => { | ||
| const {element} = await renderTab(); | ||
| expect(element.expression).toBe(''); | ||
| }); | ||
|
|
||
| it('should allow updating properties', async () => { | ||
| const {element} = await renderTab(); | ||
|
|
||
| element.label = 'Updated Label'; | ||
| element.name = 'updated-name'; | ||
| element.expression = '@updated==true'; | ||
| await element.updateComplete; | ||
|
|
||
| expect(element.label).toBe('Updated Label'); | ||
| expect(element.name).toBe('updated-name'); | ||
| expect(element.expression).toBe('@updated==true'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when rendering slots', () => { | ||
| it('should render default slot content', async () => { | ||
| const element = await fixture<AtomicTab>(html` | ||
| <atomic-tab label="Test" name="test"> | ||
| <div id="slot-content">Slot Content</div> | ||
| </atomic-tab> | ||
| `); | ||
|
|
||
| const slotContent = element.querySelector('#slot-content'); | ||
| expect(slotContent).toBeInTheDocument(); | ||
| expect(slotContent?.textContent).toBe('Slot Content'); | ||
| }); | ||
| }); | ||
| }); |
55 changes: 55 additions & 0 deletions
55
packages/atomic/src/components/search/atomic-tab/atomic-tab.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import {Schema, StringValue} from '@coveo/bueno'; | ||
| import {html, LitElement} from 'lit'; | ||
| import {customElement, property, state} from 'lit/decorators.js'; | ||
| import {ValidatePropsController} from '@/src/components/common/validate-props-controller/validate-props-controller'; | ||
| import {LightDomMixin} from '@/src/mixins/light-dom'; | ||
|
|
||
| /** | ||
| * The `atomic-tab` component represents an individual tab within the `atomic-tab-manager` component. | ||
| * It must be used as a child of the `atomic-tab-manager` component to function correctly. | ||
alexprudhomme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| @customElement('atomic-tab') | ||
| export class AtomicTab extends LightDomMixin(LitElement) { | ||
| /** | ||
| * The label to display on the tab. | ||
| */ | ||
| @property({type: String, reflect: true}) label!: string; | ||
|
|
||
| /** | ||
| * The internal name of the atomic tab. | ||
| */ | ||
| @property({type: String, reflect: true}) name!: string; | ||
|
|
||
| /** | ||
| * The [constant query expression (`cq`)](https://docs.coveo.com/en/2830/searching-with-coveo/about-the-query-expression#constant-query-expression-cq) to apply when the tab is the active one. | ||
| */ | ||
| @property({type: String, reflect: true}) public expression: string = ''; | ||
|
|
||
| @state() public error!: Error; | ||
|
|
||
| constructor() { | ||
| super(); | ||
|
|
||
| new ValidatePropsController( | ||
| this, | ||
| () => ({ | ||
| label: this.label, | ||
| name: this.name, | ||
| }), | ||
| new Schema({ | ||
| label: new StringValue({required: true, emptyAllowed: false}), | ||
| name: new StringValue({required: true, emptyAllowed: false}), | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| return html`<slot></slot>`; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'atomic-tab': AtomicTab; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
packages/atomic/src/components/search/tabs/atomic-tab/atomic-tab.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.