Skip to content

Commit

Permalink
Removed redundant "prefix" from names (deephaven#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed May 21, 2024
1 parent 0c3ee53 commit f83ab39
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions plugins/ui/src/js/src/elements/ElementConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const ELEMENT_NAME = {
export type ElementName = typeof ELEMENT_NAME;

export const ELEMENT_PREFIX = {
iconPrefix: 'deephaven.ui.icons.' as const,
htmlPrefix: 'deephaven.ui.html.' as const,
icon: 'deephaven.ui.icons.' as const,
html: 'deephaven.ui.html.' as const,
};

export type ElementPrefix = {
iconPrefix: `${typeof ELEMENT_PREFIX.iconPrefix}${keyof typeof icons}`;
htmlPrefix: `${typeof ELEMENT_PREFIX.htmlPrefix}${keyof ReactHTML}`;
icon: `${typeof ELEMENT_PREFIX.icon}${keyof typeof icons}`;
html: `${typeof ELEMENT_PREFIX.html}${keyof ReactHTML}`;
};
8 changes: 4 additions & 4 deletions plugins/ui/src/js/src/elements/HTMLElementUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { ELEMENT_KEY, ElementNode, isElementNode } from './ElementUtils';
* For example, `deephaven.ui.html.div` would be rendered as `<div>`.
* The props are passed directly to the HTML element as attributes.
*/
export type HTMLElementNode = ElementNode<ElementPrefix['htmlPrefix']>;
export type HTMLElementNode = ElementNode<ElementPrefix['html']>;

export function isHTMLElementNode(obj: unknown): obj is HTMLElementNode {
return (
isElementNode(obj) &&
(obj as HTMLElementNode)[ELEMENT_KEY].startsWith(ELEMENT_PREFIX.htmlPrefix)
(obj as HTMLElementNode)[ELEMENT_KEY].startsWith(ELEMENT_PREFIX.html)
);
}

Expand All @@ -22,6 +22,6 @@ export function isHTMLElementNode(obj: unknown): obj is HTMLElementNode {
* @param name Name of the element
* @returns The HTML tag name for the element
*/
export function getHTMLTag(name: ElementPrefix['htmlPrefix']): keyof ReactHTML {
return name.substring(ELEMENT_PREFIX.htmlPrefix.length) as keyof ReactHTML;
export function getHTMLTag(name: ElementPrefix['html']): keyof ReactHTML {
return name.substring(ELEMENT_PREFIX.html.length) as keyof ReactHTML;
}
10 changes: 4 additions & 6 deletions plugins/ui/src/js/src/elements/IconElementUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@ import { ELEMENT_KEY, ElementNode, isElementNode } from './ElementUtils';
* For example, `deephaven.ui.icons.vsBell` will render the icon named `vsBell`.
* The props are passed directly to the icon component.
*/
export type IconElementNode = ElementNode<ElementPrefix['iconPrefix']>;
export type IconElementNode = ElementNode<ElementPrefix['icon']>;

export function isIconElementNode(obj: unknown): obj is IconElementNode {
return (
isElementNode(obj) &&
(obj as IconElementNode)[ELEMENT_KEY].startsWith(ELEMENT_PREFIX.iconPrefix)
(obj as IconElementNode)[ELEMENT_KEY].startsWith(ELEMENT_PREFIX.icon)
);
}

export function getIcon(
name: ElementPrefix['iconPrefix']
): icons.IconDefinition {
export function getIcon(name: ElementPrefix['icon']): icons.IconDefinition {
return icons[
name.substring(ELEMENT_PREFIX.iconPrefix.length) as keyof typeof icons
name.substring(ELEMENT_PREFIX.icon.length) as keyof typeof icons
] as icons.IconDefinition;
}

0 comments on commit f83ab39

Please sign in to comment.