-
Notifications
You must be signed in to change notification settings - Fork 48
chore: add toolbar example as a pattern (story only) #560
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
elycheea
merged 13 commits into
carbon-design-system:main
from
devadula-nandan:toolbar-pattern
Jun 4, 2025
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cad631f
chore: add toolbar example as a pattern (story only)
devadula-nandan 9900ef2
fix: lint, format, license
devadula-nandan 0533885
refactor: scss styles and add caret class name
devadula-nandan bbe5eb0
chore: add docs for the pattern building of toolbar
devadula-nandan 8af1054
chore: yarn format
devadula-nandan 35b7d75
fix: lint
devadula-nandan 80b7075
Update packages/web-components/src/patterns/toolbar/__stories__/toolb…
devadula-nandan ef5e8d5
refactor: everything about how we deliver patterns consistently
devadula-nandan d99f733
fix: lint and license
devadula-nandan 440dfee
fix: lint
devadula-nandan a1e8cc1
chore: remove irrelevant docs information
devadula-nandan f8e105f
chore: add basic html
devadula-nandan a268807
chore: update docs
devadula-nandan 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
Large diffs are not rendered by default.
Oops, something went wrong.
2,706 changes: 2,706 additions & 0 deletions
2,706
examples/web-components/toolbar/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 @@ | ||
| { | ||
| "name": "carbon-web-components-icon-button-example", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "description": "Sample project for getting started with the Web Components from Carbon.", | ||
| "license": "Apache-2", | ||
| "main": "index.html", | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "clean": "rimraf node_modules dist .cache", | ||
| "dev": "vite" | ||
| }, | ||
| "dependencies": { | ||
| "@carbon/styles": "^1.34.0", | ||
| "@carbon/web-components": "latest", | ||
| "sass": "^1.64.1" | ||
| }, | ||
| "devDependencies": { | ||
| "vite": "5.2.13", | ||
| "rimraf": "^3.0.2" | ||
| } | ||
| } |
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,83 @@ | ||
| /** | ||
| * @license | ||
| * | ||
| * Copyright IBM Corp. 2025 | ||
| * | ||
| * This source code is licensed under the Apache-2.0 license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import '@carbon/web-components/es/components/stack/index.js'; | ||
| import '@carbon/web-components/es/components/icon-button/index.js'; | ||
| import '@carbon/web-components/es/components/dropdown/index.js'; | ||
| import '@carbon/web-components/es/components/overflow-menu/index.js'; | ||
|
|
||
| document.addEventListener('DOMContentLoaded', () => { | ||
| document.querySelectorAll('.toolbar cds-dropdown').forEach((component) => { | ||
| if (component.shadowRoot) { | ||
| const style = document.createElement('style'); | ||
| style.textContent = ` | ||
| .cds--list-box { | ||
| border-block-end: none !important; | ||
| } | ||
| `; | ||
| component.shadowRoot.appendChild(style); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| // roving keyboard navigation utility | ||
| /** | ||
| * Initializes roving tabindex for keyboard navigation within a container. | ||
| * @param {HTMLElement} container - The container element containing the buttons. | ||
| */ | ||
| function initRovingTabIndex(container) { | ||
| const buttons = Array.from(container.children).flatMap((el) => | ||
| Array.from(el.children) | ||
| ); | ||
| if (buttons.length === 0) return; | ||
|
|
||
| buttons.forEach((btn, index) => | ||
| btn.setAttribute('tabindex', index === 0 ? '0' : '-1') | ||
| ); | ||
|
|
||
| /** | ||
| * Updates the active index for keyboard navigation and sets focus on the corresponding button. | ||
| * @param {number} newIndex - The index of the button to be activated. | ||
| */ | ||
| function updateActiveIndex(newIndex) { | ||
| buttons.forEach((btn, i) => | ||
| btn.setAttribute('tabindex', i === newIndex ? '0' : '-1') | ||
| ); | ||
| buttons[newIndex].focus(); | ||
| } | ||
|
|
||
| container.addEventListener('keydown', (event) => { | ||
| const currentIndex = buttons.findIndex( | ||
| (btn) => btn.getAttribute('tabindex') === '0' | ||
| ); | ||
|
|
||
| let newIndex = currentIndex; | ||
| if (event.key === 'ArrowRight') { | ||
| newIndex = (currentIndex + 1) % buttons.length; | ||
| } else if (event.key === 'ArrowLeft') { | ||
| newIndex = (currentIndex - 1 + buttons.length) % buttons.length; | ||
| } else { | ||
| return; | ||
| } | ||
|
|
||
| updateActiveIndex(newIndex); | ||
| event.preventDefault(); | ||
| }); | ||
|
|
||
| container.addEventListener('click', (event) => { | ||
| const clickedIndex = buttons.indexOf(event.target); | ||
| if (clickedIndex !== -1) { | ||
| updateActiveIndex(clickedIndex); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| document.addEventListener('DOMContentLoaded', () => { | ||
| document.querySelectorAll('.toolbar').forEach(initRovingTabIndex); | ||
| }); |
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,64 @@ | ||
| // | ||
| // Copyright IBM Corp. 2024 | ||
| // | ||
| // This source code is licensed under the Apache-2.0 license found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| // | ||
|
|
||
| @use '@carbon/styles/scss/reset'; | ||
| @use '@carbon/styles/scss/theme'; | ||
| @use '@carbon/styles/scss/themes'; | ||
|
|
||
| // :root { | ||
| // @include theme.theme(themes.$g100); // change this to check all themes | ||
| // } | ||
| .toolbar { | ||
| display: inline-flex; | ||
| background: var(--cds-layer); | ||
|
|
||
| svg { | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| &[orientation='vertical'] { | ||
| max-inline-size: 2.5rem; | ||
| } | ||
| } | ||
|
|
||
| .toolbar-group { | ||
| flex-direction: row; | ||
| border-block-end: 1px solid var(--cds-border-subtle-01, #c6c6c6); | ||
| border-inline-end: 1px solid var(--cds-border-subtle-01, #c6c6c6); | ||
|
|
||
| &[orientation='vertical'] { | ||
| border-inline-end: none; | ||
| max-inline-size: 2.5rem; | ||
|
|
||
| &:last-child { | ||
| border-block-end: none; | ||
| } | ||
| } | ||
|
|
||
| &:last-child { | ||
| border-inline-end: none; | ||
| } | ||
| } | ||
|
|
||
| // css for adding caret through class name | ||
| .toolbar-button-caret { | ||
| position: relative; | ||
|
|
||
| &::before { | ||
| position: absolute; | ||
| background: linear-gradient( | ||
| to right bottom, | ||
| transparent 50%, | ||
| var(--cds-icon-primary, #161616) 50% | ||
| ); | ||
| block-size: calc(0.125rem + 0.25rem); | ||
| content: ''; | ||
| inline-size: calc(0.125rem + 0.25rem); | ||
| inset-block-end: 0.175rem; | ||
| inset-inline-end: 0.175rem; | ||
| } | ||
| } |
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,20 @@ | ||
| /** | ||
| * @license | ||
| * | ||
| * Copyright IBM Corp. 2025 | ||
| * | ||
| * This source code is licensed under the Apache-2.0 license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
| import { resolve } from 'path'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| build: { | ||
| rollupOptions: { | ||
| input: { | ||
| main: resolve(__dirname, 'index.html'), | ||
| }, | ||
| }, | ||
| }, | ||
| }); |
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.
Let’s remove the
package-locksince we don’t need to include these in examples.Uh oh!
There was an error while loading. Please reload this page.
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.
@elycheea, i had to refactor a lot of this structure, to be consistent with how we are delivering patterns. taking reference from ibm products.
also adds a complete lit example instead html, being consistent with ibm-products
i also had to add a lit plugin for vite config to load lit example styles in storybook.
pls have a second look when you get some time. 😄