Skip to content

Conversation

snowystinger
Copy link
Member

@snowystinger snowystinger commented Jan 6, 2020

Closes https://jira.corp.adobe.com/browse/RSP-1467

Open questions:
Which components get a slot?

  • containers? (doesn't seem like enough)
  • semantic? (does that include divider? form elements?)
  • all? (seems like a lot)
    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:

  • Included link to corresponding Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exist for this component).
  • Looked at the Accessibility Standard and/or talked to @mijordan about Accessibility for this feature.

📝 Test Instructions:

🧢 Your Team:

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
@snowystinger snowystinger changed the title Semantic elements and layout WIP: Semantic elements and layout Jan 6, 2020
@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

Copy link
Member

@LFDanLu LFDanLu left a 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

slot = 'divider',
...otherProps
} = props;
let {[slot]: slotClassName} = useSlotProvider();
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean?

Copy link
Member Author

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

Copy link
Member Author

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 {
Copy link
Member

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 {
Copy link
Member

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>) => {
Copy link
Member

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>) => {
Copy link
Member

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?

Copy link
Member Author

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>) => {
Copy link
Member

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)}>
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds fine to me

@adobe-bot
Copy link

Build successful! View the storybook

// transforms?
}

type globalVals = 'initial' | 'inherit' | 'unset';
Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

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?: {
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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??
Copy link
Member

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
Copy link
Member

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});
Copy link
Member

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});
Copy link
Member

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};
Copy link
Member

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'})

Copy link
Member Author

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)

Copy link
Member Author

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?

Copy link
Member

@devongovett devongovett Jan 18, 2020

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 {
Copy link
Member

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...

@adobe-bot
Copy link

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
Copy link
Member

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?: {
Copy link
Member

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});
Copy link
Member

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?

Copy link
Member Author

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});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

@snowystinger snowystinger changed the title WIP: Semantic elements and layout Semantic elements and layout Jan 21, 2020
@adobe-bot
Copy link

Build successful! View the storybook

@adobe-bot
Copy link

Build successful! View the storybook

devongovett
devongovett previously approved these changes Jan 23, 2020
Copy link
Member

@devongovett devongovett left a 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],
Copy link
Member

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],
Copy link
Member

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.

@adobe-bot
Copy link

Build successful! View the storybook

Copy link
Member

@ktabors ktabors left a 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",
Copy link
Member

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",
Copy link
Member

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) {
Copy link
Member

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'}}
Copy link
Member

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

Copy link
Member Author

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 () {
Copy link
Member

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?

Copy link
Member Author

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",
Copy link
Member

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';
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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>) => {
Copy link
Member

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????

Copy link
Member Author

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

tag, but Section doesn't mean much to people
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}>
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@adobe-bot
Copy link

Build successful! View the storybook

@snowystinger snowystinger merged commit 2ee8329 into master Jan 23, 2020
@snowystinger snowystinger deleted the semantic-elements-and-layout branch January 23, 2020 21:46
devongovett pushed a commit that referenced this pull request Jul 25, 2024
Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com>
Co-authored-by: Rob Snow <rsnow@adobe.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants