Skip to content

refactor: move component types into component specific interfaces files #9527

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
Show file tree
Hide file tree
Changes from 8 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
64 changes: 35 additions & 29 deletions packages/calcite-components/.storybook/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import {
Kind,
Width,
SelectionMode,
ArrowType,
DisplayMode,
ToggleDisplay,
Layout,
Dir,
ButtonType,
InteractionMode,
IconType,
DeterminateType,
FillType,
LabelType,
ClickType,
CollapseDirection,
TextType,
Mode,
SelectionAppearance,
} from "../../calcite-components/src/components/interfaces.ts";
import { ArrowType } from "../src/components/carousel/interfaces.ts";
import { BlockSectionToggleDisplay } from "../src/components/block-section/interfaces.ts";
import { TileSelectGroupDir } from "../src/components/tile-select-group/interfaces.ts";
import { TileSelectType } from "../src/components/tile-select/interfaces.ts";
import { TableInteractionMode } from "../src/components/table/interfaces.ts";
import { DeterminateType } from "../src/components/loader/interfaces.ts";
import { MeterFillType, MeterLabelType } from "../src/components/meter/interfaces.ts";
import { DropdownClickType } from "../src/components/dropdown/interfaces.ts";
import { TextType } from "../src/components/input/interfaces.ts";
import { TimeZoneMode } from "../src/components/input-time-zone/interfaces.ts";
import { DisplayMode } from "../src/components/sheet/interfaces.ts";
import { ShellDisplayMode } from "../src/components/shell/interfaces.ts";

interface AttributeMetadata<T> {
values: T[];
Expand All @@ -43,20 +43,21 @@ interface CommonAttributes {
selectionMode: AttributeMetadata<SelectionMode>;
arrowType: AttributeMetadata<ArrowType>;
displayMode: AttributeMetadata<DisplayMode>;
toggleDisplay: AttributeMetadata<ToggleDisplay>;
toggleDisplay: AttributeMetadata<BlockSectionToggleDisplay>;
layout: AttributeMetadata<Layout>;
dir: AttributeMetadata<Dir>;
buttonType: AttributeMetadata<ButtonType>;
interactionMode: AttributeMetadata<InteractionMode>;
dir: AttributeMetadata<TileSelectGroupDir>;
buttonType: AttributeMetadata<TileSelectType>;
interactionMode: AttributeMetadata<TableInteractionMode>;
iconType: AttributeMetadata<IconType>;
determinateType: AttributeMetadata<DeterminateType>;
fillType: AttributeMetadata<FillType>;
labelType: AttributeMetadata<LabelType>;
clickType: AttributeMetadata<ClickType>;
fillType: AttributeMetadata<MeterFillType>;
labelType: AttributeMetadata<MeterLabelType>;
clickType: AttributeMetadata<DropdownClickType>;
collapseDirection: AttributeMetadata<CollapseDirection>;
textType: AttributeMetadata<TextType>;
mode: AttributeMetadata<Mode>;
mode: AttributeMetadata<TimeZoneMode>;
selectionAppearance: AttributeMetadata<SelectionAppearance>;
shellDisplayMode: AttributeMetadata<ShellDisplayMode>;
}

const logicalFlowPositionOptions: LogicalFlowPosition[] = ["inline-start", "inline-end", "block-start", "block-end"];
Expand All @@ -77,8 +78,8 @@ const selectionModeOptions: SelectionMode[] = [
"multiple",
];
const arrowTypeOptions: ArrowType[] = ["inline", "edge", "none"];
const displayModeOptions: DisplayMode[] = ["dock", "float", "overlay"];
const toggleDisplayOptions: ToggleDisplay[] = ["button", "switch"];
const displayModeOptions: DisplayMode[] = ["float", "overlay"];
const toggleDisplayOptions: BlockSectionToggleDisplay[] = ["button", "switch"];
const layoutOptions: Layout[] = [
"horizontal",
"vertical",
Expand All @@ -90,14 +91,14 @@ const layoutOptions: Layout[] = [
"none",
"horizontal-single",
];
const dirOptions: Dir[] = ["ltr", "rtl"];
const buttonTypeOptions: ButtonType[] = ["radio", "checkbox"];
const interactionModeOptions: InteractionMode[] = ["interactive", "static"];
const dirOptions: TileSelectGroupDir[] = ["ltr", "rtl"];
const buttonTypeOptions: TileSelectType[] = ["radio", "checkbox"];
const interactionModeOptions: TableInteractionMode[] = ["interactive", "static"];
const iconTypeOptions: IconType[] = ["chevron", "caret", "ellipsis", "overflow", "plus-minus"];
const determinateTypeOptions: DeterminateType[] = ["determinate", "indeterminate"];
const fillTypeOptions: FillType[] = ["single", "range"];
const labelTypeOptions: LabelType[] = ["percent", "units"];
const clickTypeOptions: ClickType[] = ["click", "hover"];
const fillTypeOptions: MeterFillType[] = ["single", "range"];
const labelTypeOptions: MeterLabelType[] = ["percent", "units"];
const clickTypeOptions: DropdownClickType[] = ["click", "hover"];
const collapseDirectionOptions: CollapseDirection[] = ["down", "up"];
const textTypeOptions: TextType[] = [
"text",
Expand All @@ -111,8 +112,9 @@ const textTypeOptions: TextType[] = [
"time",
"date",
];
const modeOptions: Mode[] = ["offset", "name"];
const modeOptions: TimeZoneMode[] = ["offset", "name"];
const selectionAppearanceOptions: SelectionAppearance[] = ["icon", "border"];
const shellDisplayModeOptions: ShellDisplayMode[] = ["dock", "float", "overlay"];

export const ATTRIBUTES: CommonAttributes = {
alignment: {
Expand Down Expand Up @@ -215,4 +217,8 @@ export const ATTRIBUTES: CommonAttributes = {
values: selectionAppearanceOptions,
defaultValue: selectionAppearanceOptions[0],
},
shellDisplayMode: {
values: shellDisplayModeOptions,
defaultValue: shellDisplayModeOptions[0],
},
};
26 changes: 14 additions & 12 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { Alignment, Appearance, Columns, FlipContext, IconType, Kind, Layout, LogicalFlowPosition, Position, Scale, SelectionAppearance as SelectionAppearance1, SelectionMode, Status, Width } from "./components/interfaces";
import { Alignment, Appearance, CollapseDirection, FlipContext, IconType, Kind, Layout, LogicalFlowPosition, Position, Scale, SelectionAppearance as SelectionAppearance1, SelectionMode, Status, Width } from "./components/interfaces";
import { RequestedItem } from "./components/accordion/interfaces";
import { RequestedItem as RequestedItem1 } from "./components/accordion-item/interfaces";
import { ActionMessages } from "./components/action/assets/action/t9n";
import { EffectivePlacement, LogicalPlacement, MenuPlacement, OverlayPositioning, ReferenceElement } from "./utils/floating-ui";
import { ActionBarMessages } from "./components/action-bar/assets/action-bar/t9n";
import { Columns } from "./components/action-group/interfaces";
import { ActionGroupMessages } from "./components/action-group/assets/action-group/t9n";
import { ActionPadMessages } from "./components/action-pad/assets/action-pad/t9n";
import { AlertDuration, Sync } from "./components/alert/interfaces";
Expand Down Expand Up @@ -61,7 +62,7 @@ import { ListItemMessages } from "./components/list-item/assets/list-item/t9n";
import { MenuMessages } from "./components/menu/assets/menu/t9n";
import { MenuItemMessages } from "./components/menu-item/assets/menu-item/t9n";
import { MenuItemCustomEvent } from "./components/menu-item/interfaces";
import { MeterLabelType } from "./components/meter/interfaces";
import { MeterFillType, MeterLabelType } from "./components/meter/interfaces";
import { ModalMessages } from "./components/modal/assets/modal/t9n";
import { NoticeMessages } from "./components/notice/assets/notice/t9n";
import { PaginationMessages } from "./components/pagination/assets/pagination/t9n";
Expand Down Expand Up @@ -95,12 +96,13 @@ import { TipManagerMessages } from "./components/tip-manager/assets/tip-manager/
import { TreeItemSelectDetail } from "./components/tree-item/interfaces";
import { ValueListMessages } from "./components/value-list/assets/value-list/t9n";
import { ListItemAndHandle } from "./components/value-list-item/interfaces";
export { Alignment, Appearance, Columns, FlipContext, IconType, Kind, Layout, LogicalFlowPosition, Position, Scale, SelectionAppearance as SelectionAppearance1, SelectionMode, Status, Width } from "./components/interfaces";
export { Alignment, Appearance, CollapseDirection, FlipContext, IconType, Kind, Layout, LogicalFlowPosition, Position, Scale, SelectionAppearance as SelectionAppearance1, SelectionMode, Status, Width } from "./components/interfaces";
export { RequestedItem } from "./components/accordion/interfaces";
export { RequestedItem as RequestedItem1 } from "./components/accordion-item/interfaces";
export { ActionMessages } from "./components/action/assets/action/t9n";
export { EffectivePlacement, LogicalPlacement, MenuPlacement, OverlayPositioning, ReferenceElement } from "./utils/floating-ui";
export { ActionBarMessages } from "./components/action-bar/assets/action-bar/t9n";
export { Columns } from "./components/action-group/interfaces";
export { ActionGroupMessages } from "./components/action-group/assets/action-group/t9n";
export { ActionPadMessages } from "./components/action-pad/assets/action-pad/t9n";
export { AlertDuration, Sync } from "./components/alert/interfaces";
Expand Down Expand Up @@ -151,7 +153,7 @@ export { ListItemMessages } from "./components/list-item/assets/list-item/t9n";
export { MenuMessages } from "./components/menu/assets/menu/t9n";
export { MenuItemMessages } from "./components/menu-item/assets/menu-item/t9n";
export { MenuItemCustomEvent } from "./components/menu-item/interfaces";
export { MeterLabelType } from "./components/meter/interfaces";
export { MeterFillType, MeterLabelType } from "./components/meter/interfaces";
export { ModalMessages } from "./components/modal/assets/modal/t9n";
export { NoticeMessages } from "./components/notice/assets/notice/t9n";
export { PaginationMessages } from "./components/pagination/assets/pagination/t9n";
Expand Down Expand Up @@ -247,7 +249,7 @@ export namespace Components {
/**
* Specifies the type of the icon in the header inherited from the `calcite-accordion`.
*/
"iconType": "chevron" | "caret" | "plus-minus";
"iconType": Extract<"chevron" | "caret" | "plus-minus", IconType>;
/**
* Specifies the size of the component inherited from the `calcite-accordion`.
*/
Expand Down Expand Up @@ -1858,7 +1860,7 @@ export namespace Components {
/**
* Specifies the direction of the collapse.
*/
"collapseDirection": "down" | "up";
"collapseDirection": CollapseDirection;
/**
* When `true`, hides the component's content area.
*/
Expand Down Expand Up @@ -3252,7 +3254,7 @@ export namespace Components {
/**
* Specifies the component's display, where `"single"` displays a single color and `"range"` displays a range of colors based on provided `low`, `high`, `min` or `max` values.
*/
"fillType": "single" | "range";
"fillType": MeterFillType;
/**
* The `id` of the form that will be associated with the component. When not set, the component will be associated with its ancestor form element, if any.
*/
Expand Down Expand Up @@ -3630,7 +3632,7 @@ export namespace Components {
/**
* Specifies the direction of the collapse.
*/
"collapseDirection": "down" | "up";
"collapseDirection": CollapseDirection;
/**
* When `true`, hides the component's content area.
*/
Expand Down Expand Up @@ -7955,7 +7957,7 @@ declare namespace LocalJSX {
/**
* Specifies the type of the icon in the header inherited from the `calcite-accordion`.
*/
"iconType"?: "chevron" | "caret" | "plus-minus";
"iconType"?: Extract<"chevron" | "caret" | "plus-minus", IconType>;
"onCalciteInternalAccordionItemClose"?: (event: CalciteAccordionItemCustomEvent<void>) => void;
"onCalciteInternalAccordionItemSelect"?: (event: CalciteAccordionItemCustomEvent<RequestedItem1>) => void;
/**
Expand Down Expand Up @@ -9653,7 +9655,7 @@ declare namespace LocalJSX {
/**
* Specifies the direction of the collapse.
*/
"collapseDirection"?: "down" | "up";
"collapseDirection"?: CollapseDirection;
/**
* When `true`, hides the component's content area.
*/
Expand Down Expand Up @@ -11153,7 +11155,7 @@ declare namespace LocalJSX {
/**
* Specifies the component's display, where `"single"` displays a single color and `"range"` displays a range of colors based on provided `low`, `high`, `min` or `max` values.
*/
"fillType"?: "single" | "range";
"fillType"?: MeterFillType;
/**
* The `id` of the form that will be associated with the component. When not set, the component will be associated with its ancestor form element, if any.
*/
Expand Down Expand Up @@ -11526,7 +11528,7 @@ declare namespace LocalJSX {
/**
* Specifies the direction of the collapse.
*/
"collapseDirection"?: "down" | "up";
"collapseDirection"?: CollapseDirection;
/**
* When `true`, hides the component's content area.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from "../../utils/dom";
import { CSS_UTILITY } from "../../utils/resources";
import { getIconScale } from "../../utils/component";
import { FlipContext, Position, Scale, SelectionMode } from "../interfaces";
import { FlipContext, Position, Scale, SelectionMode, IconType } from "../interfaces";
import { componentFocusable } from "../../utils/component";
import { SLOTS, CSS, IDS } from "./resources";
import { RequestedItem } from "./interfaces";
Expand Down Expand Up @@ -74,7 +74,7 @@ export class AccordionItem implements ConditionalSlotComponent {
*
* @internal
*/
@Prop() iconType: "chevron" | "caret" | "plus-minus";
@Prop() iconType: Extract<"chevron" | "caret" | "plus-minus", IconType>;

/**
* The containing `accordion` element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {
updateMessages,
} from "../../utils/t9n";
import { SLOTS as ACTION_MENU_SLOTS } from "../action-menu/resources";
import { Columns, Layout, Scale } from "../interfaces";
import { Layout, Scale } from "../interfaces";
import { OverlayPositioning } from "../../utils/floating-ui";
import { slotChangeHasAssignedElement } from "../../utils/dom";
import { Columns } from "./interfaces";
import { ActionGroupMessages } from "./assets/action-group/t9n";
import { ICONS, SLOTS, CSS } from "./resources";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Columns = 1 | 2 | 3 | 4 | 5 | 6;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export interface ItemKeyboardEvent {
keyboardEvent: KeyboardEvent;
}

export type DropdownClickType = "click" | "hover";
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { HeadingLevel } from "../functional/Heading";
import { SLOTS as PANEL_SLOTS } from "../panel/resources";
import { OverlayPositioning } from "../../utils/floating-ui";
import { CollapseDirection } from "../interfaces";
import { FlowItemMessages } from "./assets/flow-item/t9n";
import { CSS, ICONS, SLOTS } from "./resources";

Expand Down Expand Up @@ -83,7 +84,7 @@ export class FlowItem
*
* @internal
*/
@Prop() collapseDirection: "down" | "up" = "down";
@Prop() collapseDirection: CollapseDirection = "down";

/**
* When `true`, the component is collapsible.
Expand Down
11 changes: 11 additions & 0 deletions packages/calcite-components/src/components/input/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export type InputPlacement = "vertical" | "horizontal" | "none";
export type NumberNudgeDirection = "up" | "down";
export type SetValueOrigin = "initial" | "connected" | "user" | "reset" | "direct";
export type TextType =
| "text"
| "textarea"
| "email"
| "password"
| "tel"
| "number"
| "search"
| "file"
| "time"
| "date";
23 changes: 0 additions & 23 deletions packages/calcite-components/src/components/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Note: using `.d.ts` file extension will exclude it from the output build */
export type Alignment = "start" | "center" | "end";
export type Appearance = "solid" | "outline" | "outline-fill" | "transparent";
export type Columns = 1 | 2 | 3 | 4 | 5 | 6;
export type FlipContext = "both" | "start" | "end";
export type Kind = "brand" | "danger" | "info" | "inverse" | "neutral" | "warning" | "success";
export type Layout =
Expand Down Expand Up @@ -30,27 +29,5 @@ export type SelectionMode =
export type Scale = "s" | "m" | "l";
export type Status = "invalid" | "valid" | "idle";
export type Width = "auto" | "half" | "full";
export type ArrowType = "inline" | "edge" | "none";
export type DisplayMode = "dock" | "float" | "overlay";
export type ToggleDisplay = "button" | "switch";
export type Dir = "ltr" | "rtl";
export type ButtonType = "radio" | "checkbox";
export type InteractionMode = "interactive" | "static";
export type IconType = "chevron" | "caret" | "ellipsis" | "overflow" | "plus-minus";
export type DeterminateType = "determinate" | "indeterminate";
export type FillType = "single" | "range";
export type LabelType = "percent" | "units";
export type ClickType = "click" | "hover";
export type CollapseDirection = "down" | "up";
export type TextType =
| "text"
| "textarea"
| "email"
| "password"
| "tel"
| "number"
| "search"
| "file"
| "time"
| "date";
export type Mode = "offset" | "name";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type DeterminateType = "determinate" | "indeterminate";
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type MeterLabelType = "percent" | "units";
export type MeterFillType = "single" | "range";
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/meter/meter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { intersects } from "../../utils/dom";
import { createObserver } from "../../utils/observers";
import { CSS } from "./resources";
import { MeterLabelType } from "./interfaces";
import { MeterFillType, MeterLabelType } from "./interfaces";

@Component({
tag: "calcite-meter",
Expand All @@ -45,7 +45,7 @@ export class Meter implements FormComponent, LoadableComponent, LocalizedCompone
@Prop({ reflect: true }) disabled = false;

/** Specifies the component's display, where `"single"` displays a single color and `"range"` displays a range of colors based on provided `low`, `high`, `min` or `max` values. */
@Prop({ reflect: true }) fillType: "single" | "range" = "range";
@Prop({ reflect: true }) fillType: MeterFillType = "range";

/**
* The `id` of the form that will be associated with the component.
Expand Down
3 changes: 2 additions & 1 deletion packages/calcite-components/src/components/panel/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
updateMessages,
} from "../../utils/t9n";
import { OverlayPositioning } from "../../utils/floating-ui";
import { CollapseDirection } from "../interfaces";
import { PanelMessages } from "./assets/panel/t9n";
import { CSS, ICONS, SLOTS } from "./resources";

Expand Down Expand Up @@ -94,7 +95,7 @@ export class Panel
*
* @internal
*/
@Prop() collapseDirection: "down" | "up" = "down";
@Prop() collapseDirection: CollapseDirection = "down";

/**
* When `true`, the component is collapsible.
Expand Down
Loading
Loading