Skip to content

Commit 477575c

Browse files
committed
WIP config
1 parent bd0b217 commit 477575c

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

src/components/Field/FieldBase.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Icon, Variant } from '@/components';
44
import clsx from 'clsx';
55
import { ReactElement, useState } from 'react';
66
import { FieldContext } from './FieldContext';
7+
import { ConfigManager } from '@/components/utils/config/ConfigManager';
8+
import { ConfigComponent } from '@/components/utils/config/ConfigComponent';
79

810
interface FieldBaseProps {
911
actions?: React.ReactNode;
@@ -32,7 +34,7 @@ export const getStateIcon = (valid: boolean | undefined): ReactElement | undefin
3234
);
3335
}
3436

35-
const FieldBaseProps = ({
37+
const FieldBase: React.FunctionComponent & ConfigComponent = ({
3638
actions,
3739
className,
3840
children,
@@ -91,7 +93,9 @@ export const propTypes = {
9193
variant: PropTypes.string,
9294
}
9395

94-
FieldBaseProps.displayName = 'FieldBase';
95-
FieldBaseProps.propTypes = propTypes;
96+
FieldBase.displayName = 'FieldBase';
97+
FieldBase.propTypes = propTypes;
98+
FieldBase.config = new ConfigManager();
99+
FieldBase.config.addNamespace('classes')
96100

97-
export default FieldBaseProps;
101+
export default FieldBase;

src/components/utils/config/Config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export class Config {
2+
private config: Record<string, string> = {};
3+
4+
public extend(key: string, value: any): void {
5+
if (this.has(key)) {
6+
7+
}
8+
}
9+
10+
public has(key: string): boolean {
11+
return Object.prototype.hasOwnProperty.call(this.config, key);
12+
}
13+
14+
public set(key: string, value: string): void {
15+
this.config[key] = value;
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ConfigManager } from '@/components/utils/config/ConfigManager';
2+
3+
export type ConfigComponent = {
4+
config: ConfigManager;
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Config } from '@/components/utils/config/Config';
2+
3+
export class ConfigManager {
4+
private config: Record<string, Config> = {};
5+
6+
public addNamespace(key: string): void {
7+
if (!Object.prototype.hasOwnProperty.call(this.config, key)) {
8+
this.config[key] = new Config();
9+
}
10+
}
11+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './components'
1+
export * from '@/components'

0 commit comments

Comments
 (0)