Comments (4)
I feel like we could also use a shorthand for those component definitions that looks something like this, which would give us the withComponent()
class method:
function createPrimerComponent(Element, mapProps) {
const Component = props => <Element {...mapProps(props)} />
Component.withComponent = other => createPrimerComponent(other, mapProps)
return Component
}
const Box = createPrimerComponent('div', boxMap)
const Text = createPrimerComponent('span', textMap)
const Heading = Text.withComponent('h1')
Heading.h1 = Heading
Heading.h2 = Heading.withComponent('h2')
// etc.
from react.
We chatted about this IRL this morning and decided that as a first step we'll just include all the Primer utilities in the utility map, and then later on improve the mapping to split utilities into different groups and possibly restrict certain utilities from being used on certain components ❇️
from react.
One thing I suggested was using decorators to return modified versions of components, e.g.
import {whitelist} from './utils/decorators'
@whitelist('id', 'hidden', 'aria-*')
export default class Component {
render() {
// the whitelist() decorator would modify the props by moving id, hidden,
// and aria-* props into a "whitelisted" object prop
const {x, whitelisted, children} = this.props
return (
<div className={`util-${x}`} {...whitelisted}>
{children}
</div>
)
}
}
For functional components it would look something like this:
import {whitelist} from './utils/decorators'
const Component = ({x, whitelisted, children}) => (
<div className={`util-${x}`} {...whitelisted}>
{children}
</div>
)
export default whitelist('id', 'hidden', 'aria-*')(Component)
One benefit of this approach is that the decorator function could return a component class with propTypes
that include the whitelisted keys.
from react.
It seems like we're not ready for this level of unification across all components, so I'm going to close this as OBE for now.
from react.
Related Issues (20)
- NavList.Item active state should show up as bold, but doesn't. HOT 2
- Sub-component pattern cause error when used in React Server Components HOT 1
- Get ActionBar axe clean
- Type checking is too slow HOT 3
- Clean up custom element styled class names
- Underline nav: Doesn't work well on the smallest breakpoints HOT 11
- Release Tracking
- Setting `required` to `input` element within `TextInput` HOT 2
- TypeError: CSS.supports is not a function when running Jest tests HOT 2
- Active `NavList.Item` is incorrectly missing bold styling HOT 4
- The theme object inflates bundle size. HOT 1
- Release Tracking
- The `useAnchoredPosition` hook returns generic refs for Element, which always requires a type assertion by the user
- TreeView: Remove aria-describedby when leading and trailing visuals do not exist HOT 2
- Does the Primer Design System have card components or similar card-like components? HOT 1
- Release Tracking HOT 1
- TreeView: Add support for external styling HOT 2
- TexInput `onClick` focus behavior broken with `type=date` on Safari
- `Dialog` should allow wrapping content, header, and footer (for example in `Suspense` or some context) HOT 1
- Utils should be exported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.