From 5fa5858c8d3470f94e105a4f40cc562467c74ff8 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Wed, 12 Jul 2023 16:16:21 -0700 Subject: [PATCH] Clean up types - not super necessary to have a separate file for it, these types are only used within EuiPortal - use `as const` array and typeof instead of `keyof` - simplify insert positions map typing --- src/components/portal/portal.tsx | 9 +++++++-- src/components/portal/portal.types.ts | 29 --------------------------- 2 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 src/components/portal/portal.types.ts diff --git a/src/components/portal/portal.tsx b/src/components/portal/portal.tsx index 1c439b23512..bb3fae6706c 100644 --- a/src/components/portal/portal.tsx +++ b/src/components/portal/portal.tsx @@ -17,7 +17,12 @@ import { createPortal } from 'react-dom'; import { EuiNestedThemeContext } from '../../services'; import { useEuiComponentDefaults } from '../provider/component_defaults'; -import { insertPositions } from './portal.types'; +const INSERT_POSITIONS = ['after', 'before'] as const; +type EuiPortalInsertPosition = (typeof INSERT_POSITIONS)[number]; +const insertPositions: Record = { + after: 'afterend', + before: 'beforebegin', +}; export interface EuiPortalProps { /** @@ -28,7 +33,7 @@ export interface EuiPortalProps { * If not specified, `EuiPortal` will insert itself * into the end of the `document.body` by default */ - insert?: { sibling: HTMLElement; position: 'before' | 'after' }; + insert?: { sibling: HTMLElement; position: EuiPortalInsertPosition }; /** * Optional ref callback */ diff --git a/src/components/portal/portal.types.ts b/src/components/portal/portal.types.ts deleted file mode 100644 index 735e4875e46..00000000000 --- a/src/components/portal/portal.types.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { keysOf } from '../common'; - -interface InsertPositionsMap { - after: InsertPosition; - before: InsertPosition; -} - -export const insertPositions: InsertPositionsMap = { - after: 'afterend', - before: 'beforebegin', -}; - -export type EuiPortalInsertPosition = keyof typeof insertPositions; - -export const INSERT_POSITIONS: EuiPortalInsertPosition[] = - keysOf(insertPositions); - -export interface EuiPortalInsertion { - sibling: HTMLElement; - position: EuiPortalInsertPosition; -}