-
Notifications
You must be signed in to change notification settings - Fork 81
Convert cf-component-form to Fela #133
Conversation
1cb46b6
to
f65feb6
Compare
}); | ||
|
||
const addLayoutProp = (children, layout) => | ||
React.Children.map(children, (child, index) => { |
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.
nice approach
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.
NVM, I grok this now.
borderLeft: theme.main.borderLeft, | ||
borderRight: theme.main.borderRight, | ||
borderBottom: theme.main.borderBottom, | ||
...clearFix() |
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.
👍
padding: theme.legend.padding, | ||
marginBottom: theme.legend.marginBottom, | ||
borderBottom: theme.legend.borderBottom, | ||
'@media (min-width: 720px)': layout === 'horizontal' |
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 like how flexible we could express styling
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.
please see my comments
|
||
const FormHeader = ({ className, title }) => ( | ||
<div className={className}> | ||
<Heading size={4}> |
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 was h3 before, why use h4 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.
Because it's more similar to the old version where we remove margin when used inside of form (we should not do stuff like this) but our headings come with fixed margin. We most likely make more style changes pretty soon since we don't really use cf-component-form as we should.
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.
Let's just use react-dom here. Also I don't think form header should have any <h*>
elements at all, form elements can be used anywhere. If you are within the same outline context, going from <h1>
to <h3>
it may confuse a11y speech readers.
Just use a div and style it your way.
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. I still used h3 since it matches the old styles. We will redesign all forms pretty soon anyway (more info coming soon).
@@ -37,4 +39,24 @@ const applyTheme = (ComponentToWrap, theme) => { | |||
return ThemedComponent; | |||
}; | |||
|
|||
export { createComponent, applyTheme, ThemeProvider, color }; | |||
const createComponentStyles = (styleFunctions, component) => { |
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.
please add a description about use case for this HOC.
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. I've documented all cf-style-container
functions and added a test for createComponentStyles
.
|
||
const FormHeader = ({ className, title }) => ( | ||
<div className={className}> | ||
<Heading size={4}> |
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.
Let's just use react-dom here. Also I don't think form header should have any <h*>
elements at all, form elements can be used anywhere. If you are within the same outline context, going from <h1>
to <h3>
it may confuse a11y speech readers.
Just use a div and style it your way.
|
||
### Aliased functions from fela and react-fela | ||
|
||
We proxy/alias some useful functions from fela without changing their behaviour. See the original documentation for more details. We wrap all Fela APIs so we can eventually switch Fela to a different CSS in JS lib if ever needed. |
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 highly doubt we could just switch to any css in js lib but just by wrapping these couple of functions. I have not seen any other css in js lib that does the same thing.
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.
Most of them share the same camelCase CSS in JS styles, so you can use any renderer if there's better. Btw, that's why projects like polished can be shared. It's still nice to have one cf-style-container
toolbox.
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.
Polished is just a bunch of "css preprocessor mixins" for CSS-in-JS solutions, basically, just a bunch of simple, basically pure functions. Fela has a lot of behavior that can't be expressed by these simple signatures. Replacing things is never really easy. Back in the days, people thought having an ORM layer would make switch the RDBMS easy, I lol'ed. Anyway, I digress, it's not important.
checkBaseTheme(baseTheme, 'FormTheme'); | ||
return { | ||
background: 'white', | ||
border: `1px solid ${baseTheme.colorGrayLight}`, |
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.
Is there a shorthand plugin that'll allow us to DCE this? Would be nice if we could get the best of both worlds.
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.
Not sure what you mean by this.
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.
Something like expandShorthand({border: ''}) => {borderTop, borderRight...}
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.
We should call this atomization rather than DCE. This would be even better:
...expandBorder('1px solid black')
output
borderTopColor: 'black',
borderLeftColor: 'black',
borderBottomColor: 'black',
borderRightColor: 'black',
borderTopColor: 'black',
borderLeftStyle: 'solid',
borderBottomStyle: 'solid',
borderRightStyle: 'solid',
borderTopWidth: '1px',
borderLeftWidth: '1px',
borderBottomWidth: '1px',
borderRightWidth: '1px'
); | ||
} | ||
} | ||
const FormLabel = ({ children, className }) => ( |
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.
Can we get back to classes please? We'll love to have a ref when interoping with other DOM manipulation libs. Also, you'd think this may be faster because of some old blog post and some ancient twitter message, but it actually isn't.
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.
We'll love to have a ref when interoping with other DOM manipulation libs
That sounds like something we definitely want to avoid?
you'd think this may be faster because of some old blog post and some ancient twitter message, but it actually isn't.
It will be with Fiber.
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.
Also, I like them because it's less code to write and it promotes not using internal state.
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.
We'd like to avoid using refs, but can't. Refs also isn't just something used by DOM manip libs too, tho that's a big issue because tooltip and such. Let's wait til fiber.
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.
Well, if that's everyone's opinion you should open a new PR and revert it everywhere since we use functional components within all new cf-ui codebase. I don't like it. If we really need refs, we can do it on per instance basis.
|
||
const FormFieldset = ({ legend, children, styles }) => ( | ||
<fieldset className={styles.mainStyles}> | ||
{' '} |
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.
Why?
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.
Fixed.
handleFirstNameChange(firstName) { | ||
this.setState({ firstName }); | ||
handleFirstNameChange(e) { | ||
this.setState({ firstName: e.value }); |
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.
Thanks deity
connect, | ||
combineRules, | ||
createComponentStyles | ||
}; |
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 still don't know why this package is called cf-style-container? It doesn't contain any styles. This looks like cf-util-styles to me.
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.
We wanted to have all style related stuff under cf-style.
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.
Then why is it called container?
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.
because naming is hard, especially at the beginning when you don't exactly know what will go inside, complain to @jwineman, his idea
abfc352
to
e6d6612
Compare
This is ready to go!