-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for app styles #2
Comments
Potential Solve For CSS InheritanceIn order to enable targeted css based on a state that exists above it in terms of inheritance I propose the following composer: // ./ClassComposer.jsx
import React from 'react';
import classNames from 'classnames';
import omit from 'lodash/omit';
const ClassComposer = (Component, props, styles) => {
const ClassComposer = class extends React.Component {
render () {
const newProps = omit(this.props, [
'className',
]);
const className = classNames(this.props.className, this.props.inheritedClasses);
return (
<Component className={className} {...newProps} />
);
}
};
return ClassComposer;
};
export default ClassComposer; ExampleThis is how it would be used in practice. At the highest level you have a component with a boolean in state that can be toggled. For this example we'll call the component // ./Parent.jsx
import React from 'react';
import classNames from 'classnames';
import Child from './Child/Component';
class Parent extends React.Component {
constructor (props) {
super(props);
this.state = {
mySpecialClassName: true,
};
}
render () {
const inheritableClases = classNames({
mySpecialClassName: this.state.mySpecialClassName,
});
const className = classNames('parent', inheritableClases);
return (
<div className={className}>
<p>Paragraph 1.</p>
<Child inheritedClasses={inheritableClases} className='child' />
</div>
);
}
}
export default Parent; The child component will then inherit the entire chain as it's className propr which you can use to add more classes to a chain (in this case // ./Child/Component.jsx
import React from 'react';
import classNames from 'classnames';
import ClassComposer from '../ClassComposer';
import GrandChild from './GrandChild/Component';
const BaseChild = (props) => {
const newPassableClasses = 'alongTheWay';
const className = classNames(props.className, newPassableClasses);
const inheritableClases = classNames(props.inheritedClasses, newPassableClasses);
return (
<div className={className}>
<p>Paragraph 2.</p>
<GrandChild inheritedClasses={inheritableClases} className='grand-child' />
</div>
);
};
const Child = ClassComposer(
BaseChild,
(props) => props
);
export default Child; Finally, the grand child component will have all the inherited classes from the Parent and Child components, but not the component-specific classes. // ./Child/GrandChild/Component.jsx
import React from 'react';
import ClassComposer from '../../ClassComposer';
const BaseGrandChild = (props) => {
return (
<p className={props.className}>Paragraph 3.</p>
);
};
const GrandChild = ClassComposer(
BaseGrandChild,
(props) => props
);
export default GrandChild; When <div class="parent mySpecialClassName">
<p>Paragraph 1.</p>
<div class="child mySpecialClassName alongTheWay">
<p>Paragraph 2.</p>
<p class="grand-child mySpecialClassName alongTheWay">Paragraph 3.</p>
</div>
</div> Once the boolean is toggled off, the output will look like the following: <div class="parent">
<p>Paragraph 1.</p>
<div class="child alongTheWay">
<p>Paragraph 2.</p>
<p class="grand-child alongTheWay">Paragraph 3.</p>
</div>
</div> |
You can see a demo of that proposal here. https://github.com/The-Politico/demo-css-inheritance You could probably make an argument that it should be its own npm module so we don't have to copy and paste this file into a utils folder every time we start a new project. |
Proposal 1
Use CSS modules and colocate SCSS and component files.
Proposal 2
Colocate selectors with reducers.
Selectors should operate on the same state as is defined in the reducer.
Prune the state in another place, if the reducer state is only a piece of the app's store.
Proposal 3
Separate files structure by domain instead of by function.
Separated by function.
Separated by domain.
Proposal 4
Each directory should define all exports in a single file,
index.js
and all other modules should only consume the exports defined in that file.The text was updated successfully, but these errors were encountered: