-
Notifications
You must be signed in to change notification settings - Fork 248
feat(color-loupe): migrate sp-color-loupe component to 2nd-gen #6147
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
blunteshwar
wants to merge
9
commits into
color-loupe-migration
Choose a base branch
from
claude-do-the-honors
base: color-loupe-migration
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
9 commits
Select commit
Hold shift + click to select a range
32a62b0
feat(color-loupe): implement Color Loupe component with base function…
blunteshwar 257afe2
Merge branch 'main' into claude-do-the-honors
blunteshwar c07e84e
refactor(color-loupe): added migration planning and docs
blunteshwar 758d969
fix(color-loupe): fixed styling
blunteshwar 688e358
Merge branch 'color-loupe-migration' into claude-do-the-honors
blunteshwar 087c548
chore(color-loupe): add TODO for opacity-checkerboard migration
blunteshwar 067bbe6
chore(color-loupe): reverting some changes
blunteshwar cffaead
feat(color-loupe): enhance color loupe functionality and documentation
blunteshwar 50b7660
refactor(color-loupe): rename States story to OpenAndClosedStates and…
blunteshwar 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
47 changes: 47 additions & 0 deletions
47
2nd-gen/packages/core/components/color-loupe/ColorLoupe.base.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,47 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { property } from 'lit/decorators.js'; | ||
|
|
||
| import { SpectrumElement } from '@spectrum-web-components/core/element/index.js'; | ||
|
|
||
| import { COLOR_LOUPE_DEFAULT_COLOR } from './ColorLoupe.types.js'; | ||
|
|
||
| /** | ||
| * A visual magnifier that shows the currently picked color, including | ||
| * transparency over an opacity checkerboard, inside a loupe shape. | ||
| * | ||
| * The loupe is not an interactive control — accessibility semantics are | ||
| * provided by the parent color picker / color field. | ||
| * | ||
| * @element swc-color-loupe | ||
| */ | ||
| export abstract class ColorLoupeBase extends SpectrumElement { | ||
| // ───────────────── | ||
| // SHARED API | ||
| // ───────────────── | ||
|
|
||
| /** | ||
| * Whether the loupe is visible. When `false` the loupe is hidden via | ||
| * CSS opacity and transform transitions. | ||
| */ | ||
| @property({ type: Boolean, reflect: true }) | ||
| public open = false; | ||
|
|
||
| /** | ||
| * The CSS color value to display inside the loupe. | ||
| * Supports any valid CSS color string, including those with alpha | ||
| * transparency (which reveals the checkerboard behind). | ||
| */ | ||
| @property({ type: String }) | ||
| public color = COLOR_LOUPE_DEFAULT_COLOR; | ||
| } |
17 changes: 17 additions & 0 deletions
17
2nd-gen/packages/core/components/color-loupe/ColorLoupe.types.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,17 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Default color value for a newly created color loupe. | ||
| * Semi-transparent red allows the opacity checkerboard to show through. | ||
| */ | ||
| export const COLOR_LOUPE_DEFAULT_COLOR = 'rgba(255, 0, 0, 0.5)'; |
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,13 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| export * from './ColorLoupe.base.js'; | ||
| export * from './ColorLoupe.types.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
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 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { CSSResultArray, html, TemplateResult } from 'lit'; | ||
| import { classMap } from 'lit/directives/class-map.js'; | ||
|
|
||
| import { ColorLoupeBase } from '@spectrum-web-components/core/components/color-loupe'; | ||
|
|
||
| import styles from './color-loupe.css'; | ||
|
|
||
| /** | ||
| * A visual magnifier that displays the currently picked color inside a | ||
| * loupe-shaped container with an opacity checkerboard behind transparent | ||
| * colors. The loupe is a non-interactive, visual-only companion to | ||
| * color selection controls such as `<swc-color-field>`. | ||
| * | ||
| * @element swc-color-loupe | ||
| * @status preview | ||
| * @since 0.0.1 | ||
| * | ||
| * @example | ||
| * <swc-color-loupe open color="rgba(0, 128, 255, 0.7)"></swc-color-loupe> | ||
| */ | ||
| export class ColorLoupe extends ColorLoupeBase { | ||
| // ────────────────────────────── | ||
| // RENDERING & STYLING | ||
| // ────────────────────────────── | ||
|
|
||
| // TODO: Migrate opacity-checkerboard to 2nd gen and consume it here; checkerboard styling is currently hardcoded in color-loupe.css. | ||
|
|
||
| public static override get styles(): CSSResultArray { | ||
| return [styles]; | ||
| } | ||
|
|
||
| protected override render(): TemplateResult { | ||
| return html` | ||
| <div | ||
| class=${classMap({ | ||
| ['swc-ColorLoupe']: true, | ||
| })} | ||
| > | ||
| <div class="swc-ColorLoupe-checkerboard swc-ColorLoupe--clipped"></div> | ||
| <div | ||
| class="swc-ColorLoupe-colorFill swc-ColorLoupe--clipped" | ||
| style="background: ${this.color}" | ||
| ></div> | ||
| <svg aria-hidden="true" class="swc-ColorLoupe-svg" overflow="visible"> | ||
| <defs> | ||
| <path | ||
| id="loupe-path" | ||
| d="M23 61.575C19.0044 57.435 15.2591 53.0606 11.784 48.475C8.68949 44.4532 5.96348 40.1608 3.639 35.65C1.224 30.8 0 26.549 0 23C0.00319993 17.6937 1.84059 12.5516 5.20091 8.44488C8.56122 4.33815 13.2378 1.51928 18.4385 0.465803C23.6392 -0.587678 29.0442 0.189006 33.7378 2.66428C38.4314 5.13955 42.125 9.16122 44.193 14.048C45.3915 16.88 46.0061 19.9248 46 23C46 26.551 44.774 30.811 42.355 35.661C40.0274 40.1747 37.298 44.4698 34.2 48.494C30.7297 53.0728 26.9898 57.4409 23 61.575Z" | ||
| transform="translate(2, 2)" | ||
| /> | ||
| <mask id="loupe-mask"> | ||
| <rect x="0" y="0" height="100" width="100" fill="white" /> | ||
| <use href="#loupe-path" fill="black" /> | ||
| </mask> | ||
| </defs> | ||
|
|
||
| <g class="swc-ColorLoupe-loupe"> | ||
| <use | ||
| href="#loupe-path" | ||
| mask="url(#loupe-mask)" | ||
| transform="translate(2, 2)" | ||
| class="swc-ColorLoupe-innerBorder" | ||
| /> | ||
| <use | ||
| href="#loupe-path" | ||
| mask="url(#loupe-mask)" | ||
| class="swc-ColorLoupe-outerBorder" | ||
| /> | ||
| </g> | ||
| </svg> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
104 changes: 104 additions & 0 deletions
104
2nd-gen/packages/swc/components/color-loupe/color-loupe.css
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,104 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
|
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. As noted in the main file, consider updating the SVG implementation from the spectrum-two branch which also simplifies the CSS. |
||
| :host { | ||
| display: block; | ||
| position: absolute; | ||
| inset-block-end: calc((token("color-handle-size") - token("color-handle-outer-border-width")) + var(--swc-color-loupe-offset, token("color-loupe-bottom-to-color-handle"))); | ||
| inset-inline-end: calc(50% - (token("color-loupe-width") / 2)); | ||
| } | ||
|
|
||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .swc-ColorLoupe { | ||
| --_swc-color-loupe-opacity: var(--swc-color-loupe-opacity, 0); | ||
| --_swc-color-loupe-transform: var(--swc-color-loupe-transform, translateY(var(--swc-color-loupe-animation-distance, 8px))); | ||
|
|
||
| position: relative; | ||
| inline-size: token("color-loupe-width"); | ||
| block-size: token("color-loupe-height"); | ||
| pointer-events: none; | ||
| opacity: var(--_swc-color-loupe-opacity); | ||
| filter: drop-shadow(var(--swc-color-loupe-drop-shadow-x, token("drop-shadow-elevated-x")) var(--swc-color-loupe-drop-shadow-y, token("drop-shadow-elevated-y")) var(--swc-color-loupe-drop-shadow-blur, token("drop-shadow-elevated-blur")) var(--swc-color-loupe-drop-shadow-color, token("drop-shadow-elevated-color"))); | ||
| transform: var(--_swc-color-loupe-transform); | ||
| transform-origin: bottom center; | ||
| transition: | ||
| transform 100ms ease-in-out, | ||
| opacity 125ms ease-in-out; | ||
| } | ||
|
|
||
| /* Opacity checkerboard shown behind transparent picked colors. | ||
| The dark-square token has separate light/dark theme values, so | ||
| we use light-dark() with the explicit theme variants. */ | ||
| .swc-ColorLoupe-checkerboard { | ||
| position: absolute; | ||
| inset-block-start: 2px; | ||
| inset-inline-start: 2px; | ||
| inline-size: 100%; | ||
| block-size: 100%; | ||
| background: repeating-conic-gradient(light-dark(var(--swc-opacity-checkerboard-square-dark-light), var(--swc-opacity-checkerboard-square-dark-dark)) 0% 25%, token("opacity-checkerboard-square-light") 0% 50%) 0 0 / token("opacity-checkerboard-square-size-medium") token("opacity-checkerboard-square-size-medium"); | ||
| } | ||
|
|
||
| /* Color fill layer — displays the picked color */ | ||
| .swc-ColorLoupe-colorFill { | ||
| position: absolute; | ||
| inset-block-start: 2px; | ||
| inset-inline-start: 2px; | ||
| inline-size: 100%; | ||
| block-size: 100%; | ||
| } | ||
|
|
||
| /* Clip to the loupe teardrop shape */ | ||
| .swc-ColorLoupe--clipped { | ||
| clip-path: path( | ||
| "M23 61.575C19.0044 57.435 15.2591 53.0606 11.784 48.475C8.68949 44.4532 5.96348 40.1608 3.639 35.65C1.224 30.8 0 26.549 0 23C0.00319993 17.6937 1.84059 12.5516 5.20091 8.44488C8.56122 4.33815 13.2378 1.51928 18.4385 0.465803C23.6392 -0.587678 29.0442 0.189006 33.7378 2.66428C38.4314 5.13955 42.125 9.16122 44.193 14.048C45.3915 16.88 46.0061 19.9248 46 23C46 26.551 44.774 30.811 42.355 35.661C40.0274 40.1747 37.298 44.4698 34.2 48.494C30.7297 53.0728 26.9898 57.4409 23 61.575Z" | ||
| ); | ||
| } | ||
|
|
||
| /* SVG overlay — inherits host dimensions */ | ||
| .swc-ColorLoupe-svg { | ||
| position: absolute; | ||
| inline-size: inherit; | ||
| block-size: inherit; | ||
| } | ||
|
|
||
| /* Inner border: filled with the picked color + thin stroke */ | ||
| .swc-ColorLoupe-innerBorder { | ||
| fill: none; | ||
| stroke: var(--swc-color-loupe-inner-border-color, token("color-loupe-inner-border")); | ||
| stroke-width: var(--swc-color-loupe-inner-border-width, token("color-loupe-inner-border-width")); | ||
| } | ||
|
|
||
| /* Outer border: unfilled with wider stroke */ | ||
| .swc-ColorLoupe-outerBorder { | ||
| fill: none; | ||
| stroke: var(--swc-color-loupe-outer-border-color, token("color-loupe-outer-border")); | ||
| stroke-width: calc(var(--swc-color-loupe-outer-border-width, token("color-loupe-outer-border-width")) + 2px); | ||
| } | ||
|
|
||
| /* Compensates for sub-pixel rounding in RTL that shifts the loupe */ | ||
| :host(:dir(rtl)) { | ||
| inset-inline-end: calc(50% - (token("color-loupe-width") / 2) - 1px); | ||
| } | ||
|
|
||
| :host([open]) { | ||
| --swc-color-loupe-opacity: 1; | ||
| --swc-color-loupe-transform: translate(0, 0); | ||
| } | ||
|
|
||
| @media (forced-colors: active) { | ||
| .swc-ColorLoupe-outerBorder { | ||
| --swc-color-loupe-outer-border-color: CanvasText; | ||
| } | ||
| } | ||
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 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| import { defineElement } from '@spectrum-web-components/core/element/index.js'; | ||
|
|
||
| import { ColorLoupe } from './ColorLoupe.js'; | ||
|
|
||
| export * from './ColorLoupe.js'; | ||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'swc-color-loupe': ColorLoupe; | ||
| } | ||
| } | ||
| defineElement('swc-color-loupe', ColorLoupe); |
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.
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.
There are some rendering issues with this SVG - I wonder if you could copy in from the Spectrum CSS spectrum-two version instead?
The
loupe-pathis not positioned correctly in this current version. Removing the transform at least in browser caused a different issue. I hid the color and checkerboard for this screenshot to better see the issue.