Last active
July 31, 2016 09:10
-
-
Save taion/ac60a7e54fb02e000b3a39fd3bb1e944 to your computer and use it in GitHub Desktop.
Embarrassing strawman API proposal that hopefully gets the point across
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { buttonHook } from './Button'; | |
// This is _not_ supposed to be a real API. It's only intended to describe what | |
// I'm looking for. It's almost intentionally awful. | |
const formClassName = makeClass({ | |
border: '1 px solid grey', | |
[s`> ${buttonHook}`]: buttonHook({ | |
margin: '0 1rem', | |
}), | |
}); | |
export default function InlineForm(props) { | |
return ( | |
<form | |
{...props} | |
className={classNames(props.className, formClassName)} | |
/> | |
); | |
} | |
// The idea is that you can do: | |
const form = ( | |
<InlineForm> | |
<EmailInput /> | |
<PasswordInput /> | |
<LoginButton /> | |
</InlineForm> | |
); | |
// Where <LoginButton> renders a <Button>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { buttonHook } from './Button'; | |
// This is _not_ supposed to be a real API. It's only intended to describe what | |
// I'm looking for. It's almost intentionally awful. | |
const toolbarClassName = makeClass({ | |
border: '1 px solid black', | |
[s`> ${buttonHook}`]: buttonHook({ | |
margin: '0 0.5rem', | |
// If you try to set font-family or something here, throw. | |
}), | |
}); | |
export default function Toolbar(props) { | |
return ( | |
<div | |
{...props} | |
className={classNames(props.className, toolbarClassName)} | |
/> | |
); | |
} |
Yup – so the question is something like... this lets you write .parent .child
, but you'd need select()
or something from @vjeux's https://gist.github.com/vjeux/8e27dd06c64dc566bfee705e1b19cb18 to handle e.g. .parent > :last-child
.
To me, that feels like a bit of a disadvantage; .parent .child
, .parent > .child
, and .parent > .child:last-child
feel like similar enough concepts that the syntax should also look similar.
Trying to move discussion to styled-components/spec#5.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can see how glamor can avoid the potential precedence issues with e.g. CSS modules, though. That's pretty cool.