Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions 2nd-gen/packages/core/components/meter/Meter.base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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 { PropertyValues } from 'lit';
import { property } from 'lit/decorators.js';

import { SpectrumElement } from '@spectrum-web-components/core/element/index.js';
import {
LINEAR_PROGRESS_VALID_SIZES,
LinearProgressMixin,
SizedMixin,
} from '@spectrum-web-components/core/mixins/index.js';

import { METER_VARIANTS, type MeterVariant } from './Meter.types.js';

/**
* A non-focusable, read-only bar that shows a value inside a fixed range.
* Implements the WAI-ARIA `meter` role on the shadow `.swc-Meter` element
* (the host carries no ARIA).
*
* @attribute {ElementSize} size - The size of the meter.
*/
export abstract class MeterBase extends LinearProgressMixin(
SizedMixin(SpectrumElement, {
validSizes: LINEAR_PROGRESS_VALID_SIZES,
defaultSize: 'm',
})
) {
/**
* The size of the meter.
*
* @default m
*/
declare public size: (typeof LINEAR_PROGRESS_VALID_SIZES)[number];

// ─────────────────────────
// API TO OVERRIDE
// ─────────────────────────

/**
* @internal
*
* A readonly array of all valid variants for the meter. Concrete
* subclasses re-declare with their own valid set so validation logic
* resolves against `(this.constructor as typeof MeterBase).VARIANTS`.
*/
static readonly VARIANTS: readonly string[] = METER_VARIANTS;

/**
* The variant of the meter. Drives the bar fill color.
*/
@property({ type: String, reflect: true })
public variant: MeterVariant = 'informative';

// ──────────────────────
// IMPLEMENTATION
// ──────────────────────

protected override update(changes: PropertyValues): void {
if (window.__swc?.DEBUG) {
const constructor = this.constructor as typeof MeterBase;
if (!constructor.VARIANTS.includes(this.variant)) {
window.__swc.warn(
this,
`<${this.localName}> element expects the "variant" attribute to be one of the following:`,
'https://opensource.adobe.com/spectrum-web-components/components/meter/#variants',
{
issues: [...constructor.VARIANTS],
}
);
}
}
super.update(changes);
}
}
19 changes: 19 additions & 0 deletions 2nd-gen/packages/core/components/meter/Meter.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 const METER_VARIANTS = [
'informative',
'positive',
'notice',
'negative',
] as const;
export type MeterVariant = (typeof METER_VARIANTS)[number];
13 changes: 13 additions & 0 deletions 2nd-gen/packages/core/components/meter/index.ts
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 './Meter.base.js';
export * from './Meter.types.js';
10 changes: 10 additions & 0 deletions 2nd-gen/packages/core/mixins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
*/

export { DisabledMixin, type DisabledInterface } from './disabled-mixin.js';
export {
LINEAR_PROGRESS_LABEL_POSITIONS,
LINEAR_PROGRESS_STATIC_COLORS,
LINEAR_PROGRESS_VALID_SIZES,
LinearProgressMixin,
type LinearProgressInterface,
type LinearProgressLabelPosition,
type LinearProgressSize,
type LinearProgressStaticColor,
} from './linear-progress-mixin.js';
export {
ObserveSlotPresence,
type SlotPresenceObservingInterface,
Expand Down
Loading
Loading