-
Notifications
You must be signed in to change notification settings - Fork 55
feat(renderComponent): merged state and props for styles and accessibility #173
Conversation
Codecov Report
@@ Coverage Diff @@
## master #173 +/- ##
=======================================
Coverage 68.02% 68.02%
=======================================
Files 101 101
Lines 1370 1370
Branches 269 260 -9
=======================================
Hits 932 932
Misses 436 436
Partials 2 2 Continue to review full report at Codecov.
|
2709529
to
780090c
Compare
}) | ||
}) | ||
|
||
it('simple merge of props and state if both are set but there are no overlapping properties', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to describe result in the test name, like props and state properties are merged together
and props properties take precedence over ones of state
for the next one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand, let's discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed with @kuzhelov and amended
src/lib/renderComponent.tsx
Outdated
@@ -83,7 +73,11 @@ const renderComponent = <P extends {}>( | |||
|
|||
// Resolve styles using resolved variables, merge results, allow props.styles to override | |||
const mergedStyles = mergeComponentStyles(componentStyles[displayName], props.styles) | |||
const styleParam: ComponentStyleFunctionParam = { props, variables: resolvedVariables } | |||
const appliedProps = { ...state, ...props } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one note - before we'll come up with a name for this 'merged' object, maybe we could use something that is a bit dumb but explicit and descriptive - like stateAndProps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks
...props, | ||
...state, | ||
}) | ||
return callable(customAccessibility || defaultAccessibility || DefaultBehavior)(props) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessibility functions end up with being provided with state only now - but previously state
data was provided as well (this was a correct and expected behavior)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jurokapsiar is this correct here?
@kuzhelov anything to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessibility need a merge of props and state. props should override state. looking at line 83, I think this is correctly implemented now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather change the name of the argument, because it is a bit misleading - to indicate that 'state' is merged to 'props'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks guys
types/theme.d.ts
Outdated
@@ -77,7 +86,7 @@ export interface ICSSInJSStyle extends React.CSSProperties { | |||
} | |||
|
|||
export interface ComponentStyleFunctionParam { | |||
props: IProps | |||
props: IState & IProps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
types/theme.d.ts
Outdated
@@ -20,7 +21,15 @@ type ObjectOf<T> = { [key: string]: T } | |||
// Props | |||
// ======================================================== | |||
|
|||
export type IProps = ObjectOf<any> | |||
export type IProps = Extendable<{ | |||
variables?: ComponentVariablesInput |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work for all the components, unfortunately (Provider
as an example) - lets keep to be generic for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, done
src/lib/renderComponent.tsx
Outdated
export interface IRenderConfig { | ||
className?: string | ||
defaultProps?: { [key: string]: any } | ||
displayName: string | ||
handledProps: string[] | ||
props: IRenderConfigProps | ||
state: { [key: string]: any } | ||
props: IProps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use the type that was used before - as IProps
is not generic enough to suite all the components if styles
and variables
are introduced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
780090c
to
d958935
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Component style function
This PR adds the ability to receive a unified (merged) object of
props
andstate
as argument to component's style functions, as well as to the accessibility behaviors.More details in the dedicated issue: #161
TODO
API Proposal
Before
After