-
Notifications
You must be signed in to change notification settings - Fork 23
feat(cellar-explorer): add objects management #1661
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
Open
pdesoyres-cc
wants to merge
6
commits into
master
Choose a base branch
from
cellar-explorer-objects-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9ed47be
feat(cc-breadcrumbs): init component
pdesoyres-cc 510ba94
feat(cc-grid): add `enableCopyToClipboard` to `link` grid cell
1e89205
refactor: move Abortable class to a generic lib
eb36e0e
feat(cc-cellar-explorer): add `abortable` mechanism for smart request…
efbb864
feat(cc-cellar-object-list): init component
d200f04
feat(cc-cellar-explorer): integrate `cc-cellar-object-list`
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { CcEvent } from '../../lib/events.js'; | ||
|
|
||
| /** | ||
| * Dispatched when a breadcrumb item is clicked. | ||
| * @extends {CcEvent<{path: Array<string>}>} | ||
| */ | ||
| export class CcBreadcrumbClickEvent extends CcEvent { | ||
| static TYPE = 'cc-breadcrumb-click'; | ||
|
|
||
| /** | ||
| * @param {{path: Array<string>}} details | ||
| */ | ||
| constructor(details) { | ||
| super(CcBreadcrumbClickEvent.TYPE, details); | ||
| } | ||
| } | ||
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,127 @@ | ||
| import { css, html, LitElement } from 'lit'; | ||
| import { ifDefined } from 'lit/directives/if-defined.js'; | ||
| import '../cc-link/cc-link.js'; | ||
| import { CcBreadcrumbClickEvent } from './cc-breadcrumbs.events.js'; | ||
|
|
||
| /** | ||
| * @import { CcBreadcrumbsItem } from './cc-breadcrumbs.types.js' | ||
| */ | ||
|
|
||
| /** | ||
| * A breadcrumb navigation component that displays a hierarchical path of items. | ||
| * | ||
| * Each breadcrumb item is clickable except the last item. | ||
| * Clicking a breadcrumb item dispatches a `CcBreadcrumbClickEvent` with the path to that item. | ||
| * | ||
| * WARNING: When a breadcrumb item's `label` is an empty string, you MUST set the `iconA11yName` value to provide accessible text for the icon. | ||
| * Otherwise, the link will have no discernible text, which is a serious accessibility issue (WCAG: Links must have discernible text). | ||
| * | ||
| * @cssdisplay block | ||
| */ | ||
| export class CcBreadcrumbs extends LitElement { | ||
| static get properties() { | ||
| return { | ||
| disabled: { type: Boolean }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix: this property is not implemented |
||
| items: { type: Array }, | ||
| }; | ||
| } | ||
|
|
||
| static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true }; | ||
|
|
||
| constructor() { | ||
| super(); | ||
|
|
||
| /** @type {Array<CcBreadcrumbsItem>} Set the items. */ | ||
| this.items = []; | ||
| } | ||
|
|
||
| /** | ||
| * @param {Event} event | ||
| * @param {Array<string>} path | ||
| */ | ||
| _onItemClick(event, path) { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| this.dispatchEvent(new CcBreadcrumbClickEvent({ path })); | ||
| } | ||
|
|
||
| render() { | ||
| /** @type {Array<string>} */ | ||
| let current = []; | ||
| const parts = this.items ?? []; | ||
|
|
||
| return html`<ul> | ||
| ${parts.map((item, index) => { | ||
| let path = [...current, item.value]; | ||
| current = path; | ||
| const isLast = index === parts.length - 1; | ||
| const label = item.label ?? item.value; | ||
|
|
||
| const itemView = | ||
| item.icon != null | ||
| ? html`<span class="item-wrapper" | ||
| ><cc-icon .icon=${item.icon} .a11yName=${item.iconA11yName}></cc-icon>${label}</span | ||
| >` | ||
| : label; | ||
|
|
||
| return html`<li aria-current=${ifDefined(isLast ? 'page' : undefined)}> | ||
| ${isLast ? itemView : ''} | ||
| ${!isLast | ||
| ? html`<cc-link href="#" @click=${/** @param {Event} event */ (event) => this._onItemClick(event, path)} | ||
| >${itemView}</cc-link | ||
| >` | ||
| : ''} | ||
| </li>`; | ||
| })} | ||
| </ul>`; | ||
| } | ||
|
|
||
| static get styles() { | ||
| return [ | ||
| // language=CSS | ||
| css` | ||
| :host { | ||
| display: block; | ||
|
|
||
| --gap: 0.5em; | ||
| } | ||
|
|
||
| ul { | ||
| align-items: end; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix: this breaks alignment for breadcrumbs with no icons. To fix your issue, you can:
|
||
| display: flex; | ||
| flex-wrap: wrap; | ||
| gap: var(--gap); | ||
| list-style: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| li { | ||
| align-items: center; | ||
| display: flex; | ||
| gap: var(--gap); | ||
| } | ||
|
|
||
| .item-wrapper { | ||
| align-items: center; | ||
| display: flex; | ||
| gap: 0.2em; | ||
| min-width: 0; | ||
| } | ||
|
|
||
| cc-icon { | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| li + li::before { | ||
| color: var(--cc-color-text-disabled, #ccc); | ||
| content: '/'; | ||
| font-size: 1.2em; | ||
| font-weight: bold; | ||
| } | ||
| `, | ||
| ]; | ||
| } | ||
| } | ||
|
|
||
| window.customElements.define('cc-breadcrumbs', CcBreadcrumbs); | ||
100 changes: 100 additions & 0 deletions
100
src/components/cc-breadcrumbs/cc-breadcrumbs.stories.js
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,100 @@ | ||
| import { html, render } from 'lit'; | ||
| import { iconRemixHome_3Line as iconHouse } from '../../assets/cc-remix.icons.js'; | ||
| import { makeStory } from '../../stories/lib/make-story.js'; | ||
| import './cc-breadcrumbs.js'; | ||
|
|
||
| export default { | ||
| tags: ['autodocs'], | ||
| title: '🧬 Atoms/<cc-breadcrumbs>', | ||
| component: 'cc-breadcrumbs', | ||
| }; | ||
|
|
||
| /** | ||
| * @import { CcBreadcrumbs } from './cc-breadcrumbs.js' | ||
| */ | ||
|
|
||
| const conf = { | ||
| component: 'cc-breadcrumbs', | ||
| }; | ||
|
|
||
| export const defaultStory = makeStory(conf, { | ||
| /** @type {Partial<CcBreadcrumbs>[]} */ | ||
| items: [ | ||
| { | ||
| items: [{ value: 'first' }, { value: 'second' }, { value: 'third' }], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export const withIconStory = makeStory(conf, { | ||
| /** @type {Partial<CcBreadcrumbs>[]} */ | ||
| items: [ | ||
| { | ||
| items: [{ value: 'home', icon: iconHouse }, { value: 'first' }, { value: 'second' }, { value: 'third' }], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export const withNoLabelStory = makeStory(conf, { | ||
| /** @type {Partial<CcBreadcrumbs>[]} */ | ||
| items: [ | ||
| { | ||
| items: [ | ||
| { value: 'home', label: '', icon: iconHouse, iconA11yName: 'Home' }, | ||
| { value: 'first' }, | ||
| { value: 'second' }, | ||
| { value: 'third' }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export const withSmallContainerStory = makeStory(conf, { | ||
| dom: /** @param {HTMLElement} container */ (container) => { | ||
| let width = '25'; | ||
|
|
||
| /** | ||
| * @param {Event & { target: { value: string }}} e | ||
| */ | ||
| function _onChange(e) { | ||
| width = e.target.value; | ||
| refresh(); | ||
| } | ||
|
|
||
| const items = [{ value: 'home', icon: iconHouse }, { value: 'first' }, { value: 'second' }, { value: 'third' }]; | ||
|
|
||
| function refresh() { | ||
| render( | ||
| html` | ||
| <div class="main"> | ||
| <div class="form"> | ||
| <label for="width">Width: (${width}%)</label> | ||
| <input type="range" id="width" .value=${String(width)} min="3" max="100" @input=${_onChange} /> | ||
| </div> | ||
| <cc-breadcrumbs .items=${items} style="width:${width}%"></cc-breadcrumbs> | ||
| </div> | ||
| `, | ||
| container, | ||
| ); | ||
| } | ||
|
|
||
| refresh(); | ||
| }, | ||
| // language=CSS | ||
| css: ` | ||
| cc-breadcrumbs { | ||
| border: 2px solid #ccc; | ||
| } | ||
| .main { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 1em; | ||
| } | ||
| .form { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.25em; | ||
| align-items: start; | ||
| } | ||
| `, | ||
| }); |
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,12 @@ | ||
| import { IconModel } from '../common.types.js'; | ||
|
|
||
| export interface CcBreadcrumbsItem { | ||
| value: string; | ||
| label?: string; | ||
| icon?: IconModel; | ||
| /** | ||
| * WARNING: When `label` is an empty string, you MUST set this value to provide accessible text for the icon. | ||
| * Otherwise, the link will have no discernible text, which is a serious accessibility issue (WCAG: Links must have discernible text). | ||
| */ | ||
| iconA11yName?: string; | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: tough one but I wonder if removing the "s" here is a good idea, it makes it very easy to get the event name wrong since the component name contains a "s" (but I do understand why it's singlar here 🤷)
Or we could use a totally different event name like
cc-navigation-requestor something like that 🤔