-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Separate Dialog Header/Heading grid areas #312
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
Changes from all commits
fe6acb7
f9df975
75d2df0
9f0c926
149cf89
b083e81
220342c
07ed0c4
523395b
1b21cdd
3bc707e
e1f4225
e944e77
4ea3612
6faf312
bae02bb
1b4c682
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,8 @@ governing permissions and limitations under the License. | |
|
|
||
| /* 12px desktop (medium scale) and 8px mobile (large scale) */ | ||
| --spectrum-dialog-close-button-padding: calc(26px - var(--spectrum-global-dimension-size-175)); | ||
|
|
||
| --spectrum-dialog-gap-size: var(--spectrum-global-dimension-size-200); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -85,19 +87,38 @@ governing permissions and limitations under the License. | |
|
|
||
| .spectrum-Dialog .spectrum-Dialog-grid { | ||
| display: grid; | ||
| grid-template-columns: var(--spectrum-dialog-padding) 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-columns: var(--spectrum-dialog-padding) auto 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-rows: auto var(--spectrum-dialog-padding) auto auto 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-areas: | ||
| "hero hero hero hero" | ||
| ". . . closeButton" | ||
| ". header header ." | ||
| ". divider divider ." | ||
| ". content content ." | ||
| ". footer buttonGroup ." | ||
| ". . . ."; | ||
| "hero hero hero hero hero" | ||
| ". . . . closeButton" | ||
| ". heading header header ." | ||
| ". divider divider divider ." | ||
| ". content content content ." | ||
| ". footer footer buttonGroup ." | ||
| ". . . . ."; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .spectrum-Dialog-heading { | ||
| grid-area: heading; | ||
|
|
||
| margin: 0; | ||
|
|
||
| font-size: var(--spectrum-dialog-title-text-size); | ||
| font-weight: var(--spectrum-dialog-title-text-font-weight); | ||
| line-height: var(--spectrum-dialog-title-text-line-height); | ||
|
|
||
| outline: none; /* Hide focus outline */ | ||
|
|
||
| padding-inline-end: var(--spectrum-dialog-gap-size); | ||
|
|
||
| &.spectrum-Dialog-heading--noHeader { | ||
| grid-area: heading-start / heading-start / header-end / header-end; | ||
| padding-inline-end: 0; | ||
| } | ||
| } | ||
|
|
||
| .spectrum-Dialog-header { | ||
| grid-area: header; | ||
| display: flex; | ||
|
|
@@ -167,24 +188,23 @@ governing permissions and limitations under the License. | |
| grid-area: buttonGroup; | ||
| /* this padding isn't built into the grid because it disappears with this buttonGroup */ | ||
| padding-block-start: var(--spectrum-global-dimension-static-size-500); | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| /* this padding should be safe as button group is always end aligned */ | ||
| padding-inline-start: var(--spectrum-dialog-gap-size); | ||
|
|
||
| &.spectrum-Dialog-buttonGroup--noFooter { | ||
| grid-area: footer-start / footer-start / buttonGroup-end / buttonGroup-end; | ||
| } | ||
| } | ||
|
|
||
| .spectrum-Dialog--dismissable { | ||
| .spectrum-Dialog-footer { | ||
| .spectrum-Dialog-buttonGroup { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| .spectrum-Dialog-heading { | ||
| flex: 1 1 auto; | ||
|
|
||
| margin: 0; | ||
|
|
||
| font-size: var(--spectrum-dialog-title-text-size); | ||
| font-weight: var(--spectrum-dialog-title-text-font-weight); | ||
| line-height: var(--spectrum-dialog-title-text-line-height); | ||
|
|
||
| outline: none; /* Hide focus outline */ | ||
| .spectrum-Dialog-footer { | ||
| grid-area: footer / footer/ buttonGroup / buttonGroup; | ||
| } | ||
| } | ||
|
|
||
| .spectrum-Dialog-closeButton { | ||
|
|
@@ -221,20 +241,15 @@ governing permissions and limitations under the License. | |
| &.spectrum-Dialog .spectrum-Dialog-grid { | ||
| display: grid; | ||
| grid-template-columns: var(--spectrum-dialog-padding) 1fr auto auto var(--spectrum-dialog-padding); | ||
| grid-template-rows: calc(var(--spectrum-dialog-padding) + var(--spectrum-dialog-fullscreen-padding-top)) auto auto 1fr var(--spectrum-dialog-padding); | ||
| grid-template-rows: var(--spectrum-dialog-padding) auto auto 1fr var(--spectrum-dialog-padding); | ||
| grid-template-areas: | ||
| ". . . . ." | ||
| ". header header buttonGroup ." | ||
| ". heading header buttonGroup ." | ||
| ". divider divider divider ." | ||
| ". content content content ." | ||
| ". . . . ."; | ||
| } | ||
|
|
||
| .spectrum-Dialog-heading { | ||
| font-size: var(--spectrum-dialog-fullscreen-header-text-size); | ||
| font-weight: var(--spectrum-dialog-fullscreen-header-text-font-weight); | ||
| } | ||
|
|
||
| .spectrum-Dialog-content { | ||
| max-height: none; | ||
| } | ||
|
|
@@ -247,23 +262,41 @@ governing permissions and limitations under the License. | |
| .spectrum-Dialog-footer { | ||
| display: none; | ||
| } | ||
|
|
||
| .spectrum-Dialog-buttonGroup { | ||
| grid-area: buttonGroup; | ||
| } | ||
| } | ||
|
|
||
| @media screen and (max-width: 700px) { | ||
| .spectrum-Dialog .spectrum-Dialog-grid { | ||
| grid-template-columns: var(--spectrum-dialog-padding) auto 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-rows: auto var(--spectrum-dialog-padding) auto auto auto 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-areas: | ||
| "hero hero hero hero hero" | ||
| ". . . . closeButton" | ||
| ". heading heading heading ." | ||
| ". header header header ." | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there be a gap between heading and header here? |
||
| ". divider divider divider ." | ||
| ". content content content ." | ||
| ". footer footer buttonGroup ." | ||
| ". . . . ."; | ||
| } | ||
| .spectrum-Dialog--fullscreen, | ||
| .spectrum-Dialog--fullscreenTakeover { | ||
|
|
||
| &.spectrum-Dialog .spectrum-Dialog-grid { | ||
| display: grid; | ||
| grid-template-columns: var(--spectrum-dialog-padding) 1fr auto auto var(--spectrum-dialog-padding); | ||
| grid-template-rows: calc(var(--spectrum-dialog-padding) + var(--spectrum-dialog-fullscreen-padding-top)) auto auto 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-columns: var(--spectrum-dialog-padding) 1fr var(--spectrum-dialog-padding); | ||
| grid-template-rows: var(--spectrum-dialog-padding) auto auto auto 1fr auto var(--spectrum-dialog-padding); | ||
| grid-template-areas: | ||
| ". . . ." | ||
| ". header header ." | ||
| ". divider divider ." | ||
| ". content content ." | ||
| ". . buttonGroup ." | ||
| ". . . ."; | ||
| ". . ." | ||
| ". heading ." | ||
| ". header ." | ||
| ". divider ." | ||
| ". content ." | ||
| ". buttonGroup ." | ||
| ". . ."; | ||
| } | ||
|
|
||
| .spectrum-Dialog-buttonGroup { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| */ | ||
|
|
||
| import {ActionButton} from '@react-spectrum/button'; | ||
| import {classNames, filterDOMProps, useSlotProps, useStyleProps} from '@react-spectrum/utils'; | ||
| import {classNames, filterDOMProps, useHasChild, useSlotProps, useStyleProps} from '@react-spectrum/utils'; | ||
| import CrossLarge from '@spectrum-icons/ui/CrossLarge'; | ||
| import {DialogContext, DialogContextValue} from './context'; | ||
| import {FocusScope} from '@react-aria/focus'; | ||
|
|
@@ -90,20 +90,25 @@ let sizeMap = { | |
|
|
||
| function BaseDialog({children, slots, size, role, ...otherProps}: SpectrumBaseDialogProps) { | ||
| let ref = useRef(); | ||
| let gridRef = useRef(); | ||
| let sizeVariant = sizeMap[size]; | ||
| let {dialogProps, titleProps} = useDialog({ref, role, ...otherProps}); | ||
|
|
||
| let hasHeader = useHasChild(`:scope > .${styles['spectrum-Dialog-header']}`, gridRef); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should i move |
||
| let hasFooter = useHasChild(`:scope > .${styles['spectrum-Dialog-footer']}`, gridRef); | ||
|
|
||
| if (!slots) { | ||
| slots = { | ||
| container: {UNSAFE_className: styles['spectrum-Dialog-grid']}, | ||
| hero: {UNSAFE_className: styles['spectrum-Dialog-hero']}, | ||
| header: {UNSAFE_className: styles['spectrum-Dialog-header']}, | ||
| heading: {UNSAFE_className: styles['spectrum-Dialog-heading'], ...titleProps}, | ||
| heading: {UNSAFE_className: classNames(styles, 'spectrum-Dialog-heading', {'spectrum-Dialog-heading--noHeader': !hasHeader}), ...titleProps}, | ||
| typeIcon: {UNSAFE_className: styles['spectrum-Dialog-typeIcon']}, | ||
| divider: {UNSAFE_className: styles['spectrum-Dialog-divider'], size: 'M'}, | ||
| content: {UNSAFE_className: styles['spectrum-Dialog-content']}, | ||
| footer: {UNSAFE_className: styles['spectrum-Dialog-footer']}, | ||
| closeButton: {UNSAFE_className: styles['spectrum-Dialog-closeButton']}, | ||
| buttonGroup: {UNSAFE_className: styles['spectrum-Dialog-buttonGroup']} | ||
| buttonGroup: {UNSAFE_className: classNames(styles, 'spectrum-Dialog-buttonGroup', {'spectrum-Dialog-buttonGroup--noFooter': !hasFooter})} | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -118,7 +123,7 @@ function BaseDialog({children, slots, size, role, ...otherProps}: SpectrumBaseDi | |
| otherProps.className | ||
| )} | ||
| ref={ref}> | ||
| <Grid slots={slots}> | ||
| <Grid slots={slots} ref={gridRef}> | ||
| {children} | ||
| </Grid> | ||
| </section> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2020 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import {RefObject, useLayoutEffect, useState} from 'react'; | ||
|
|
||
| export function useHasChild(query: string, ref: RefObject<HTMLElement>) { | ||
| let [hasChild, setHasChild] = useState(true); | ||
| useLayoutEffect(() => { | ||
| setHasChild(!!(ref.current && ref.current.querySelector(query))); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a boolean so that if the child element changes, we don't cause any unnecessary rerenders |
||
| }, [setHasChild, query, ref]); | ||
| return hasChild; | ||
| } | ||
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 the header class have a default justify?