Skip to content

Commit 40b81e4

Browse files
committed
chore(dropzone): pass sizes on to illustrated message
1 parent 87928fd commit 40b81e4

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

2nd-gen/packages/core/components/dropzone/Dropzone.base.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { property } from 'lit/decorators.js';
13+
import { PropertyValues } from 'lit';
14+
import { property, queryAssignedElements } from 'lit/decorators.js';
1415

1516
import { SpectrumElement } from '@spectrum-web-components/core/element/index.js';
1617
import { SizedMixin } from '@spectrum-web-components/core/mixins/index.js';
@@ -105,6 +106,26 @@ export abstract class DropzoneBase extends SizedMixin(SpectrumElement, {
105106
// IMPLEMENTATION
106107
// ──────────────────────────
107108

109+
@queryAssignedElements({ flatten: true, selector: 'swc-illustrated-message' })
110+
private illustratedMessages!: Element[];
111+
112+
protected override updated(changedProperties: PropertyValues): void {
113+
super.updated(changedProperties);
114+
if (changedProperties.has('size')) {
115+
this.propagateSizeToIllustratedMessage();
116+
}
117+
}
118+
119+
protected handleSlotChange(): void {
120+
this.propagateSizeToIllustratedMessage();
121+
}
122+
123+
private propagateSizeToIllustratedMessage(): void {
124+
for (const el of this.illustratedMessages) {
125+
el.setAttribute('size', this.size);
126+
}
127+
}
128+
108129
/** Timer ID for debounced dragleave — prevents flickering on child drag events. */
109130
private _dragLeaveTimer: ReturnType<typeof setTimeout> | null = null;
110131

2nd-gen/packages/swc/.storybook/preview.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ const preview = {
490490
['Rendering and styling migration analysis'],
491491
'Search',
492492
['Rendering and styling migration analysis'],
493+
'Sidenav',
494+
['Accessibility migration analysis'],
493495
'Slider',
494496
['Rendering and styling migration analysis'],
495497
'Status light',

2nd-gen/packages/swc/components/dropzone/Dropzone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class Dropzone extends DropzoneBase {
160160
return html`
161161
<div class="swc-Dropzone">
162162
<div role="status" aria-live="polite" class="swc-Dropzone-status"></div>
163-
<slot></slot>
163+
<slot @slotchange=${this.handleSlotChange}></slot>
164164
</div>
165165
`;
166166
}

2nd-gen/packages/swc/components/dropzone/stories/dropzone.stories.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,17 @@ const DROPZONE_SVG = `
7979
// swc-illustrated-message slots: default (slot="") for SVG, "heading" for h2-h6, "description" for text.
8080
// The browse button is a sibling of swc-illustrated-message inside swc-dropzone; the button-group
8181
// slot is planned but not yet implemented on swc-illustrated-message.
82-
const makeDropzoneSlot = (headingText: string) => html`
82+
// size is passed to swc-button to match the dropzone size; swc-illustrated-message receives
83+
// size automatically via swc-dropzone's slotchange propagation.
84+
const makeDropzoneSlot = (
85+
headingText: string,
86+
size: DropzoneSize = 'm'
87+
) => html`
8388
<swc-illustrated-message>
8489
${unsafeHTML(DROPZONE_SVG)}
8590
<h2 slot="heading">${headingText}</h2>
8691
</swc-illustrated-message>
87-
<swc-button variant="accent">Browse files</swc-button>
92+
<swc-button variant="accent" size=${size}>Browse files</swc-button>
8893
`;
8994

9095
// HTML string version used by the Playground so template(args) can spread all args.
@@ -153,12 +158,12 @@ export const Sizes: Story = {
153158
aria-label="${sizeLabels[size]} drop zone"
154159
style="min-inline-size: 260px;"
155160
>
156-
${makeDropzoneSlot(sizeLabels[size])}
161+
${makeDropzoneSlot(sizeLabels[size], size)}
157162
</swc-dropzone>
158163
`
159164
)}
160165
`,
161-
parameters: { flexLayout: 'row-wrap' },
166+
parameters: { flexLayout: 'column-center' },
162167
tags: ['options'],
163168
};
164169

0 commit comments

Comments
 (0)