-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* typescriptise .storybook * wip * wip * wip * form validator tests added * small changes * testing * wip * wip * wip * wip * wip * better time validation in the story * a bit of cleanup * some generic updates * wip * DEV-101 wip * add generic source and value parameters * error handling added * small fix * wip * small re-facto * remotdev & small refacto * form cleanup * remove unused tsconfig.node.json * DEV-101 * DEV-101 * fix comments
- Loading branch information
1 parent
7ddf222
commit d361bd1
Showing
25 changed files
with
1,202 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,6 @@ | ||
module.exports = { | ||
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], | ||
addons: [ | ||
'@storybook/addon-links', | ||
'@storybook/addon-essentials', | ||
'@storybook/addon-interactions', | ||
'@storybook/addon-jest', | ||
'@storybook/addon-a11y', // TODO: vite fix https://github.com/storybookjs/storybook/pull/17997 | ||
'storybook-addon-designs', | ||
], | ||
staticDirs: ['../public'], | ||
framework: '@storybook/react', | ||
core: { | ||
builder: '@storybook/builder-vite', | ||
}, | ||
async viteFinal(config, { configType }) { | ||
console.log('env', process.env.BASE_URL, process.env.STORYBOOK_FIGMA_ACCESS_TOKEN) | ||
config.base = process.env.BASE_URL || config.base | ||
|
||
// return the customized config | ||
return config | ||
}, | ||
} | ||
const register = require('ts-node-register') | ||
register({ | ||
target: 'node16', | ||
project: 'tsconfig.tsnode.json', | ||
}) | ||
module.exports = require('./main.ts') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { StorybookConfig, Options } from '@storybook/core-common' | ||
import { UserConfig } from 'vite' | ||
interface ExtendedConfig extends StorybookConfig { | ||
viteFinal?: (config: UserConfig, options: Options) => Promise<UserConfig> | ||
} | ||
const config: ExtendedConfig = { | ||
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], | ||
addons: [ | ||
'@storybook/addon-links', | ||
'@storybook/addon-essentials', | ||
'@storybook/addon-interactions', | ||
'@storybook/addon-jest', | ||
'@storybook/addon-a11y', // TODO: vite fix https://github.com/storybookjs/storybook/pull/17997 | ||
'storybook-addon-designs', | ||
], | ||
framework: '@storybook/react', | ||
core: { | ||
builder: '@storybook/builder-vite', | ||
}, | ||
async viteFinal(config) { | ||
console.log('env', process.env.BASE_URL, process.env.STORYBOOK_FIGMA_ACCESS_TOKEN) | ||
config.base = process.env.BASE_URL || config.base | ||
|
||
// return the customized config | ||
return config | ||
}, | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
declare module '*.svg' { | ||
const content: any | ||
export default content | ||
} | ||
declare module '*.jpg' { | ||
const content: any | ||
export default content | ||
} | ||
declare module '*.png' { | ||
const content: any | ||
export default content | ||
} | ||
declare module '*.css' { | ||
interface IClassNames { | ||
[className: string]: string | ||
} | ||
const classNames: IClassNames | ||
export = classNames | ||
} | ||
// declare module '*.svg' { | ||
// const content: any | ||
// export default content | ||
// } | ||
// declare module '*.jpg' { | ||
// const content: any | ||
// export default content | ||
// } | ||
// declare module '*.png' { | ||
// const content: any | ||
// export default content | ||
// } | ||
// declare module '*.css' { | ||
// interface IClassNames { | ||
// [className: string]: string | ||
// } | ||
// const classNames: IClassNames | ||
// export = classNames | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { HTMLInputTypeAttribute } from 'react' | ||
import { catchError, debounceTime, delay, filter, from, mergeMap, Observable, of, switchMap } from 'rxjs' | ||
import { createActionCreator, isActionOf } from '../store' | ||
import { ActionType, Effect } from '../store/types' | ||
import { Values, UseFormProps, FormState } from './types' | ||
|
||
const ActionTypes = { | ||
Submit: 'Form/Submit', | ||
SubmitSuccess: 'Form/SubmitSuccess', | ||
SubmitError: 'Form/SubmitError', | ||
Validate: 'Form/Validate', | ||
ValidateSuccess: 'Form/ValidateSuccess', | ||
ValidateError: 'Form/ValidateError', | ||
Reset: 'Form/Reset', | ||
SetValue: 'Form/SetValue', | ||
SetValues: 'Form/SetValues', | ||
SetTouched: 'Form/SetTouched', | ||
RegisterField: 'Form/RegisterField', | ||
UnregisterField: 'Form/UnregisterField', | ||
} as const | ||
|
||
export class ActionFactory<T extends Values> { | ||
Submit = createActionCreator(ActionTypes.Submit)<void>() | ||
SubmitSuccess = createActionCreator(ActionTypes.SubmitSuccess)<T>() | ||
|
||
SubmitError = createActionCreator(ActionTypes.SubmitError)<Error>() | ||
|
||
Validate = createActionCreator(ActionTypes.Validate)<void>() | ||
|
||
ValidateSuccess = createActionCreator(ActionTypes.ValidateSuccess)<{ [key in keyof T]?: string }>() | ||
|
||
ValidateError = createActionCreator(ActionTypes.ValidateError)<Error>() | ||
|
||
Reset = createActionCreator(ActionTypes.Reset)<void>() | ||
|
||
SetValue = createActionCreator(ActionTypes.SetValue)<{ key: keyof T; value: T[keyof T]; internal?: boolean }>() | ||
|
||
SetValues = createActionCreator(ActionTypes.SetValues)<Partial<T>>() | ||
|
||
SetTouched = createActionCreator(ActionTypes.SetTouched)<{ key: keyof T; touched: boolean }>() | ||
|
||
RegisterField = createActionCreator(ActionTypes.RegisterField)<{ | ||
key: keyof T | ||
removeValueOnUnmount?: boolean | ||
type?: HTMLInputTypeAttribute | ||
}>() | ||
UnregisterField = createActionCreator(ActionTypes.UnregisterField)<{ key: keyof T; type?: HTMLInputTypeAttribute }>() | ||
} | ||
|
||
export type FormActions<T extends Values> = ActionType<ActionFactory<T>[keyof ActionFactory<T>]> | ||
export type ActionDispatch<T extends Values> = (value: FormActions<T>) => void | ||
|
||
export type GetFormEffectsProps<T extends Values> = Omit<UseFormProps<T>, 'onValidate'> & { | ||
onValidate: (values: T) => Observable<{ [key in keyof T]?: string | undefined }> | ||
} | ||
export const getFormEffects = <T extends Values>( | ||
actions: ActionFactory<T>, | ||
propsRef: React.RefObject<GetFormEffectsProps<T>> | ||
): Array<Effect<FormState<T>, FormActions<T>>> => [ | ||
(action$) => | ||
action$.pipe( | ||
filter(() => typeof propsRef.current?.onSubmit === 'function'), | ||
isActionOf(actions.Submit), | ||
switchMap(([_, __, { values }]) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return from(propsRef.current!.onSubmit!(values)).pipe( | ||
mergeMap((values) => of(actions.SubmitSuccess(values))), | ||
catchError((err) => of(actions.SubmitError(err))) | ||
) | ||
}) | ||
), | ||
(action$) => | ||
action$.pipe( | ||
isActionOf(actions.Validate), | ||
switchMap(([_, __, { values }]) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return from(propsRef.current!.onValidate!(values)).pipe( | ||
mergeMap((values) => of(actions.ValidateSuccess(values))), | ||
catchError((err) => of(actions.ValidateError(err))) | ||
) | ||
}) | ||
), | ||
(action$) => | ||
action$.pipe( | ||
isActionOf(actions.SetValue), | ||
debounceTime(33), | ||
delay(33), | ||
switchMap((_) => of(actions.Validate(undefined))) | ||
), | ||
(action$) => | ||
action$.pipe( | ||
isActionOf(actions.RegisterField), | ||
debounceTime(33), | ||
delay(33), | ||
switchMap((_) => of(actions.Validate(undefined))) | ||
), | ||
] |
Oops, something went wrong.