-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Semantic elements and layout #149
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
Conversation
Added Image element, needs a rename, maybe Picture? Added slots to Divider/Label Added some Style stuff to Flex/Grid
…ently are removes circular dependency to use Slots in example story
Build successful! View the storybook |
Build successful! View the storybook |
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.
My initial gut feeling for your "Which components get a slot?" question is to say all components. I'm thinking that it would be cool for a end user to design an arbitrary grid-template-areas
and be able to describe where any component would go just by passing in a slot
prop. Dunno how well weirdly shaped components would fit in though so this might be unrealistic
packages/@react-spectrum/layout/src/move-to-somewhere/Image.tsx
Outdated
Show resolved
Hide resolved
slot = 'divider', | ||
...otherProps | ||
} = props; | ||
let {[slot]: slotClassName} = useSlotProvider(); |
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.
Can we do this within useStyleProps
? It already returns a class name there, and all of our components already use it, so it might be easier to maintain in a single place.
...otherProps | ||
} = props; | ||
let {[slot]: slotClassName} = useSlotProvider(); | ||
// TODO: pull out into official handling |
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.
what does this mean?
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.
referring to these functions justifyContent: ['justify-content', value => value]
i wasn't sure where they should live, i think your other comment answered it though
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.
the styleHandlers, wasn't sure where they should be, but i think your comment kinda answered it
import styles from './layout.css'; | ||
import {useSlotProvider} from '@react-spectrum/utils'; | ||
|
||
export interface FlexProps { |
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.
Should extend DOMProps and StyleProps. Also should be in @react-types
import React, {ReactElement, ReactNode, RefObject} from 'react'; | ||
import {useSlotProvider} from '@react-spectrum/utils'; | ||
|
||
export interface KeyboardProps { |
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.
same
slot?: string | ||
} | ||
|
||
export const Keyboard = React.forwardRef((props: KeyboardProps, ref: RefObject<HTMLElement>) => { |
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.
Move to typography?
slot?: string | ||
} | ||
|
||
export const Text = React.forwardRef((props: TextProps, ref: RefObject<HTMLElement>) => { |
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.
Move to typography. Did we discuss the naming of this element?
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.
no, not yet, let's discuss! :)
slot?: string | ||
} | ||
|
||
export const Heading = React.forwardRef((props: HeadingProps, ref: RefObject<HTMLElement>) => { |
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.
typography
let {[slot]: slotClassName} = useSlotProvider(); | ||
|
||
return ( | ||
<h1 {...filterDOMProps(otherProps)} ref={ref} className={classNames({}, slotClassName, className)}> |
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.
h1 should not be hard coded.
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.
yep, was leaving alone so i didn't actually implement any of these sub elements
Image has caching stuff
None of them have spectrum-
classes yet (mostly looking at typography with that statement)
types across all of them will probably need some alterations
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.
I think i'd prefer to followup with that stuff, thoughts?
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.
sounds fine to me
Build successful! View the storybook |
// transforms? | ||
} | ||
|
||
type globalVals = 'initial' | 'inherit' | 'unset'; |
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.
Hmm, we haven't included these for any other style property. Do we need them? Is the property not being set equivalent?
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.
I don't know, they are valid values, so figured they should be included and moved them to their own type so that they could be easily included on everything else should we decide we want them
also easy to delete if there is a strong feeling to not include them
type justifyContentType = 'center'| 'start'| 'end'| 'flex-start' | 'flex-end' | 'left' | 'right' | 'normal' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch' | 'safe center' | 'unsafe center' | globalVals; | ||
type justifyItemsType = 'auto' | 'normal' | 'stretch' | 'center'| 'start'| 'end'| 'flex-start' | 'flex-end' | 'self-start' | 'self-end' | 'left' | 'right' | 'baseline' | 'first baseline' | 'last baseline' | 'safe center' | 'unsafe center' | 'legacy right' | 'legacy left' | 'legacy center' | globalVals; | ||
type alignContentType = 'center'| 'start'| 'end'| 'flex-start' | 'flex-end' | 'normal' | 'baseline' | 'first baseline' | 'last baseline' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch' | 'safe center' | 'unsafe center' | globalVals; | ||
type alignItemsType = 'normal'| 'stretch'| 'center'| 'start' | 'end' | 'flex-start' | 'flex-end' | 'baseline' | 'first baseline' | 'last baseline' | 'safe center' | 'unsafe center' | globalVals; |
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.
type names should be capitalized.
justifyItems?: justifyItemsType, | ||
alignContent?: alignContentType, | ||
alignItems?: alignItemsType, | ||
placeContent?: { |
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.
What is this property? Is it duplicating alignItems
and justifyContent
? Same for placeItems
?
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.
so placeContent is a valid css property that is a shorthand for /?
however, i couldn't figure out a good validation (typescript) pattern given that it could be any combination of the two or just a single value from align-content
so I broke it up into an object... got any ideas or just remove?
https://developer.mozilla.org/en-US/docs/Web/CSS/place-content
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.
Ah ok. I think we can remove it since it's just a shorthand. Same below
align: alignItemsType | 'auto' | ||
justify?: justifyItemsType | ||
}, | ||
rowGap?: DimensionValue // not well supported in Flex, but is well supported in Grid, also, should this really be dimension value?? |
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.
Let's not include for flex then
isRequired?: boolean, | ||
necessityIndicator?: NecessityIndicator // default icon | ||
necessityIndicator?: NecessityIndicator, // default icon | ||
slot?: string |
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.
not needed (in style props)
slots, | ||
...otherProps | ||
} = props; | ||
let {styleProps} = useStyleProps(otherProps, {...baseStyleProps, ...gridStyleProps}); |
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.
Can baseStyleProps
be included as part of gridStyleProps
rather than here?
children, | ||
...otherProps | ||
} = props; | ||
let {styleProps} = useStyleProps(otherProps, {...baseStyleProps, ...flexStyleProps}); |
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.
Can baseStyleProps
be included as part of flexStyleProps
rather than here?
let defaults = { | ||
slot: 'divider' | ||
}; | ||
props = {...defaults, ...props}; |
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.
Maybe we could pass the defaults as a second param to useStyleProps
and merge them in there instead of doing this in every component?
useStyleProps(otherProps, {slot: 'divider'})
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.
would you want it as the third?
currently the signature is useStyleProps(props: StyleProps, handlers: StyleHandlers = baseStyleProps)
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.
also, do we want to set defaults for any of the styleProps object? 'style' or 'className' etc?
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.
Hmm, an alternative:
useStyleProps({slot: 'divider', ...otherProps})
TODO: find home for this, rsp? spectrum-css? | ||
*/ | ||
|
||
.flex { |
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.
sure, it's only one property though, and all the other style props on these components are inline already...
Build successful! View the storybook |
flexShrink?: number, | ||
justifySelf?: 'auto' | 'normal' | 'start' | 'end' | 'flex-start' | 'flex-end' | 'self-start' | 'self-end' | 'center' | 'left' | 'right' | 'stretch', // ... | ||
alignSelf?: 'auto' | 'normal' | 'start' | 'end' | 'flex-start' | 'flex-end' | 'self-start' | 'self-end' | 'center' | 'stretch', // ... | ||
placeSelf?: any, // don't know how to type |
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.
Remove? I think this is just a shorthand for a couple other properties represented here so probably no need for this
justifyItems?: justifyItemsType, | ||
alignContent?: alignContentType, | ||
alignItems?: alignItemsType, | ||
placeContent?: { |
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.
Ah ok. I think we can remove it since it's just a shorthand. Same below
slots, | ||
...otherProps | ||
} = props; | ||
let {styleProps} = useStyleProps(otherProps, {...gridStyleProps}); |
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.
No need to clone gridStyleProps right?
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.
🤣
children, | ||
...otherProps | ||
} = props; | ||
let {styleProps} = useStyleProps(otherProps, {...flexStyleProps}); |
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.
same
Build successful! View the storybook |
Build successful! View the storybook |
Build successful! View the storybook |
Build successful! View the storybook |
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.
Looks good. Please fix the 2 items above and then merge.
alignItems: ['align-items', passthroughStyle], | ||
alignContent: ['align-content', passthroughStyle], | ||
placeItems: ['place-items', placementStyle], | ||
placeContent: ['place-content', placementStyle], |
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.
Still think we should remove these since they're just shorthands... Looks like they're already gone in the types.
placeItems: ['place-items', placementStyle], | ||
placeContent: ['place-content', placementStyle], | ||
rowGap: ['row-gap', dimensionValue], | ||
columnGap: ['row-gap', dimensionValue], |
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.
I think these should only be in grid since they are not widely supported for flex layout. Seems done in the types already too.
Build successful! View the storybook |
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.
Seems pretty straightforward and cool
@@ -0,0 +1,40 @@ | |||
{ | |||
"name": "@react-spectrum/image", | |||
"version": "3.0.0-rc.1", |
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.
3.0.0-alpha.1
"dependencies": { | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/utils": "^3.0.0-rc.1", | ||
"@react-spectrum/provider": "^3.0.0-rc.1", |
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.
peer dependency
let {styleProps} = useStyleProps({slot: 'image', ...otherProps}); | ||
let domRef = useDOMRef(ref); | ||
|
||
if (decorative) { |
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.
!decorative
? ... I know demo component
<div | ||
{...filterDOMProps(props)} | ||
{...styleProps} | ||
style={{overflow: 'hidden'}} |
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.
if not a demo component I'd want style done differently
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.
yep, demo, i'm not doing anything with image right now
import React from 'react'; | ||
|
||
// TODO: testing :) | ||
describe('Grid', function () { |
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.
What would a grid test look like since it's basically a container for CSS and children?
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.
left over from plop, i don't know that it needs one right now, when i think of one, i'll write it
"dependencies": { | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/utils": "^3.0.0-rc.1", | ||
"@react-spectrum/provider": "^3.0.0-rc.1", |
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.
peer dependency
@@ -0,0 +1,7 @@ | |||
import React, {useContext} from 'react'; |
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.
why is there here instead of @react-spectrum/slots
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.
seemed heavy to include yet another package, @devongovett you have any preferences?
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.
Yeah I think utils is fine for this
children: ReactElement | string | ReactElement[] | ||
} | ||
|
||
export const Content = React.forwardRef((props: ContentProps, ref: RefObject<HTMLElement>) => { |
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.
Naming is hard, is there a better name for this? Content feels too generic, like I get what a header or footer is, but content could be anything. It feels more like body, but that is taken. copy, gist, text, subject, message????
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.
content is meant to be extremely generic for this, it's to represent the
So this is like, the body content of a dialog, the body content of a card etc
let {styleProps} = useStyleProps({slot: 'footer', ...otherProps}); | ||
|
||
return ( | ||
<footer {...filterDOMProps(otherProps)} {...styleProps} ref={ref}> |
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.
the slot, name, and html tag are the only difference at this time between any of these. Is there a more interesting way to generalize and compose these?
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.
eventually they will probably have some associated spectrum styles for typography
the slot is the most important part, these all have defaults for grid-area
so that people don't need to think about slots for the most part
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.
lgtm
Build successful! View the storybook |
Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com> Co-authored-by: Rob Snow <rsnow@adobe.com>
Closes https://jira.corp.adobe.com/browse/RSP-1467
Open questions:
Which components get a slot?
answer, all components through useStyleProps
list of TODO's in the PR itself, just do a search for the string on the page
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Team: