From 477575cfe0873474e2f0d9f9fbdfc09014f08e98 Mon Sep 17 00:00:00 2001 From: Eran Machiels Date: Sat, 6 Feb 2021 17:21:03 +0100 Subject: [PATCH] WIP config --- src/components/Field/FieldBase.tsx | 12 ++++++++---- src/components/utils/config/Config.ts | 17 +++++++++++++++++ src/components/utils/config/ConfigComponent.ts | 5 +++++ src/components/utils/config/ConfigManager.ts | 11 +++++++++++ src/index.ts | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 src/components/utils/config/Config.ts create mode 100644 src/components/utils/config/ConfigComponent.ts create mode 100644 src/components/utils/config/ConfigManager.ts diff --git a/src/components/Field/FieldBase.tsx b/src/components/Field/FieldBase.tsx index 93e8e9b..82f81dc 100644 --- a/src/components/Field/FieldBase.tsx +++ b/src/components/Field/FieldBase.tsx @@ -4,6 +4,8 @@ import { Icon, Variant } from '@/components'; import clsx from 'clsx'; import { ReactElement, useState } from 'react'; import { FieldContext } from './FieldContext'; +import { ConfigManager } from '@/components/utils/config/ConfigManager'; +import { ConfigComponent } from '@/components/utils/config/ConfigComponent'; interface FieldBaseProps { actions?: React.ReactNode; @@ -32,7 +34,7 @@ export const getStateIcon = (valid: boolean | undefined): ReactElement | undefin ); } -const FieldBaseProps = ({ +const FieldBase: React.FunctionComponent & ConfigComponent = ({ actions, className, children, @@ -91,7 +93,9 @@ export const propTypes = { variant: PropTypes.string, } -FieldBaseProps.displayName = 'FieldBase'; -FieldBaseProps.propTypes = propTypes; +FieldBase.displayName = 'FieldBase'; +FieldBase.propTypes = propTypes; +FieldBase.config = new ConfigManager(); +FieldBase.config.addNamespace('classes') -export default FieldBaseProps; +export default FieldBase; diff --git a/src/components/utils/config/Config.ts b/src/components/utils/config/Config.ts new file mode 100644 index 0000000..b7b9936 --- /dev/null +++ b/src/components/utils/config/Config.ts @@ -0,0 +1,17 @@ +export class Config { + private config: Record = {}; + + public extend(key: string, value: any): void { + if (this.has(key)) { + + } + } + + public has(key: string): boolean { + return Object.prototype.hasOwnProperty.call(this.config, key); + } + + public set(key: string, value: string): void { + this.config[key] = value; + } +} diff --git a/src/components/utils/config/ConfigComponent.ts b/src/components/utils/config/ConfigComponent.ts new file mode 100644 index 0000000..0a57f2b --- /dev/null +++ b/src/components/utils/config/ConfigComponent.ts @@ -0,0 +1,5 @@ +import { ConfigManager } from '@/components/utils/config/ConfigManager'; + +export type ConfigComponent = { + config: ConfigManager; +} diff --git a/src/components/utils/config/ConfigManager.ts b/src/components/utils/config/ConfigManager.ts new file mode 100644 index 0000000..486722f --- /dev/null +++ b/src/components/utils/config/ConfigManager.ts @@ -0,0 +1,11 @@ +import { Config } from '@/components/utils/config/Config'; + +export class ConfigManager { + private config: Record = {}; + + public addNamespace(key: string): void { + if (!Object.prototype.hasOwnProperty.call(this.config, key)) { + this.config[key] = new Config(); + } + } +} diff --git a/src/index.ts b/src/index.ts index cb64ac1..a68062c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export * from './components' +export * from '@/components'