Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Convert cf-component-form to Fela #133

Merged
merged 13 commits into from
Apr 4, 2017
Merged

Conversation

tajo
Copy link
Contributor

@tajo tajo commented Mar 29, 2017

This is ready to go!

@jwineman jwineman mentioned this pull request Mar 29, 2017
33 tasks
@tajo tajo changed the title [WIP] Convert Form and FormFieldError components to Fela [WIP] Convert cf-component-form to Fela Mar 29, 2017
@tajo tajo force-pushed the fela-component-form branch from 1cb46b6 to f65feb6 Compare March 31, 2017 23:14
@tajo tajo changed the title [WIP] Convert cf-component-form to Fela Convert cf-component-form to Fela Mar 31, 2017
});

const addLayoutProp = (children, layout) =>
React.Children.map(children, (child, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice approach

Copy link
Contributor

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()
Copy link
Contributor

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'
Copy link
Contributor

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

Copy link
Contributor

@sejoker sejoker left a 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}>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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) => {
Copy link
Contributor

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.

Copy link
Contributor Author

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}>
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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}`,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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...}

Copy link
Contributor Author

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 }) => (
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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}>
{' '}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

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 });
Copy link
Contributor

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
};
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

@tajo tajo force-pushed the fela-component-form branch from abfc352 to e6d6612 Compare April 4, 2017 20:41
@tajo tajo merged commit e630210 into cloudflare:master Apr 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants