-
Notifications
You must be signed in to change notification settings - Fork 536
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
Add Position components #202
Conversation
We chatted about this in Slack today and agreed that CaretBox should wrap its children in a <Position position={position}>
<Box {...boxProps}>
{children}
<Caret {...caretProps} />
</Box>
</Position> There are a couple of problems with this.
My proposed fix for this is not to render a function CaretBox(props) {
const {bg, border, borderColor} = props
const {caret, children, ...boxProps} = props
const caretProps = {bg, borderWidth: border, borderColor}
return (
<Position {...boxProps}>
{children}
<CaretBox {...caretProps} />
</Position>
)
}
CaretBox.defaultProps = {
...Position.defaultProps,
...Box.defaultProps,
position: 'relative'
} |
This seems reasonable to me. Could you add an example of what the public api would look like with a common use-case example? One thing that we talked about in the past is "caret" is the wrong name for this, caret is the name of the triangle icon usually shown in dropdowns etc. This can be a follow-up pr but we should rename this to "PointerBox" or something. |
Thanks, @broccolini! In e53aa08 I merged @emplums Block → + Box → BorderBox work and updated CaretBox accordingly. I like the name |
Okay, this is ready for review! 🤞 |
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.
This is what I expected the <Position
component would look like. I think it looks good. 💯
TODO: don't make |
This introduces first-class components for positioning:
Position
is the "base" component, and providesposition
,top
,right
,bottom
, andleft
props.Absolute
is an implementation of Position that always setsposition="absolute"
Relative
is an implementation of Position that always setsposition="relative"
Fixed
is an implementation of Position that always setsposition="fixed"
Sticky
is an implementation of Position that always setsposition="sticky"
There are tests for Absolute, Relative, Fixed, and Sticky that ensure each always gets styled as
position: <value>
, even when provided a differentposition
prop. I've deletedposition
from bothdefaultProps
andpropTypes
for each of these because they always get that value, and it can't be changed.💥⚠️ This PR also renames the
CaretBox
component toPointerBox
, which now (unconditionally) getsposition: relative
. This means that to absolutely position a PointerBox, for example, you would need to wrap it in<Absolute>
.Here's an example of a dropdown (select menu?) implemented with these components. You can paste the following example into the sandbox to see how it works:
(You can add
open mb={64}
to the<Details>
above if you want to see what it looks like open — without having to click it each time — and not overlapping the live editor.)