From f298700ba98bb6c62796c4a008aa1bd803b23eeb Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 3 May 2020 17:44:48 +0200 Subject: [PATCH] packages/core: added basic nav target implementation --- packages/core/src/api/index.ts | 1 + packages/core/src/api/navTargets/NavTarget.ts | 43 +++++++++++++++++++ packages/core/src/api/navTargets/index.ts | 18 ++++++++ packages/core/src/api/navTargets/types.ts | 35 +++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 packages/core/src/api/navTargets/NavTarget.ts create mode 100644 packages/core/src/api/navTargets/index.ts create mode 100644 packages/core/src/api/navTargets/types.ts diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts index e60a7efa18..8c8972c72c 100644 --- a/packages/core/src/api/index.ts +++ b/packages/core/src/api/index.ts @@ -16,5 +16,6 @@ export * from './api'; export * from './apis'; +export * from './navTargets'; export { FeatureFlags } from './app/FeatureFlags'; export { useApp } from './app/AppContext'; diff --git a/packages/core/src/api/navTargets/NavTarget.ts b/packages/core/src/api/navTargets/NavTarget.ts new file mode 100644 index 0000000000..ee964abb01 --- /dev/null +++ b/packages/core/src/api/navTargets/NavTarget.ts @@ -0,0 +1,43 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed 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 CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { NavTargetConfig, NavTargetOverrideConfig } from './types'; + +export class MutableNavTarget { + private effectiveConfig: NavTargetConfig = this.config; + + constructor(private readonly config: NavTargetConfig) {} + + override(overrideConfig: NavTargetOverrideConfig) { + this.effectiveConfig = { ...this.config, ...overrideConfig }; + } + + get icon() { + return this.effectiveConfig.icon; + } + + get path() { + return this.effectiveConfig.path; + } + + get title() { + return this.effectiveConfig.title; + } +} + +export function createNavTarget(config: NavTargetConfig): MutableNavTarget { + return new MutableNavTarget(config); +} diff --git a/packages/core/src/api/navTargets/index.ts b/packages/core/src/api/navTargets/index.ts new file mode 100644 index 0000000000..6c2c899f89 --- /dev/null +++ b/packages/core/src/api/navTargets/index.ts @@ -0,0 +1,18 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed 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 CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type { NavTarget, NavTargetConfig, NavTargetOverrideConfig } from './types'; +export { createNavTarget } from './NavTarget'; diff --git a/packages/core/src/api/navTargets/types.ts b/packages/core/src/api/navTargets/types.ts new file mode 100644 index 0000000000..104b8203b0 --- /dev/null +++ b/packages/core/src/api/navTargets/types.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed 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 CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { IconComponent } from '../../icons'; + +export type NavTarget = { + path: string; + icon: IconComponent; + title: string; +}; + +export type NavTargetConfig = { + path: string; + icon: IconComponent; + title: string; +}; + +export type NavTargetOverrideConfig = { + path?: string; + icon?: IconComponent; + title?: string; +};