packages/core: added basic nav target implementation

This commit is contained in:
Patrik Oldsberg
2020-05-03 17:44:48 +02:00
parent c61400c6e7
commit f298700ba9
4 changed files with 97 additions and 0 deletions
+1
View File
@@ -16,5 +16,6 @@
export * from './api';
export * from './apis';
export * from './navTargets';
export { FeatureFlags } from './app/FeatureFlags';
export { useApp } from './app/AppContext';
@@ -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);
}
+18
View File
@@ -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';
+35
View File
@@ -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;
};