Skip to content
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 some props on BottomSheet, CozyDialogs and SearchBar #2699

Merged
merged 6 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/components/DemoProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import TranspiledDemoProvider from 'cozy-ui/transpiled/react/providers/DemoProvider'
import { useCozyTheme } from 'cozy-ui/transpiled/react/providers/CozyTheme'
import TranspiledDemoProvider from 'cozy-ui/transpiled/react/providers/DemoProvider'

// Provider used in readme.md files, because we must
// use transpiled files inside readme.
Expand Down
6 changes: 5 additions & 1 deletion react/BottomSheet/BottomSheet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const defaultBottomSheetSpringConfig = {
const defaultSettings = {
mediumHeightRatio: 0.75,
mediumHeight: null,
hasMinHeightOffset: false,
isOpenMin: false
}

Expand All @@ -142,7 +143,7 @@ const BottomSheet = memo(
offset,
children
}) => {
const { mediumHeightRatio, mediumHeight, isOpenMin } = {
const { mediumHeightRatio, mediumHeight, isOpenMin, hasMinHeightOffset } = {
...defaultSettings,
...settings
}
Expand Down Expand Up @@ -244,6 +245,7 @@ const BottomSheet = memo(
isClosable,
isOpenMin,
headerRef,
offset: hasMinHeightOffset ? offset : 0,
actionButtonsHeight,
actionButtonsBottomMargin
})
Expand Down Expand Up @@ -418,6 +420,8 @@ BottomSheet.propTypes = {
mediumHeight: PropTypes.number,
/** Height of the middle snap point, expressed as a percentage of the viewport height */
mediumHeightRatio: PropTypes.number,
/** To include the offset in the min height value */
hasMinHeightOffset: PropTypes.bool,
/** To open the BottomSheet at the minimum height, if have an header */
isOpenMin: PropTypes.bool
}),
Expand Down
2 changes: 2 additions & 0 deletions react/BottomSheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import BottomSheet, { BottomSheetItem, BottomSheetTitle } from 'cozy-ui/transp
* **settings** : `<object>` – Settings that can be modified
* **mediumHeight** : `<number>` – Height in pixel of the middle snap point
* **mediumHeightRatio** : `<number>` – Height of the middle snap point, expressed as a percentage of the viewport height
* **isOpenMin** : `<boolean>` – To open the BottomSheet at the minimum height, if have an header
* **hasMinHeightOffset** : `<boolean>` – To include the offset in the min height value
* **backdrop** : `<boolean>` – To add a backdrop
* **skipAnimation** : `<boolean>` – To remove animations
* **offset** : `<number>` – Add an offset at the bottom
Expand Down
2 changes: 2 additions & 0 deletions react/BottomSheet/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export const computeMinHeight = ({
isClosable,
isOpenMin,
headerRef,
offset = 0,
actionButtonsHeight,
actionButtonsBottomMargin
}) => {
if (isClosable && !isOpenMin) return 0

return (
headerRef.current.offsetHeight +
offset +
actionButtonsHeight +
actionButtonsBottomMargin +
(getFlagshipMetadata().navbarHeight || 0) +
Expand Down
12 changes: 12 additions & 0 deletions react/BottomSheet/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ describe('computeMinHeight', () => {

expect(res).toBe(85)
})

it('should return correct value with offset', () => {
const res = computeMinHeight({
isClosable: false,
headerRef: { current: { offsetHeight: 10 } },
offset: 10,
actionButtonsHeight: 20,
actionButtonsBottomMargin: 30
})

expect(res).toBe(95)
})
})

describe('setTopPosition', () => {
Expand Down
9 changes: 8 additions & 1 deletion react/CozyDialogs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Button from 'cozy-ui/transpiled/react/Buttons'

* **componentsProps** : `<object>` – overriden properties of specific components
* **dialogTitle** : `<object>` – DialogTitle component properties
* **size** : `<string>` – Can be "s", "m" (default) or "l"
* **size** : `<string>` – Can be "small", "medium" (default), "large" or "full"
* **open** : `<boolean>` (required) – To open/close the modal
* **disableTitleAutoPadding** : `<boolean>` (optional) – Disable title padding calculation that would prevent overlapping with close and back buttons
* if set to `true` then you should handle those CSS properties by yourself or title will take 100% of width
Expand Down Expand Up @@ -205,6 +205,7 @@ const initialVariants = [{
showActions: true,
disableGutters: false,
hideTitle: false,
fullScreen: false,
withBackground: false
}]

Expand Down Expand Up @@ -264,6 +265,11 @@ const initialVariants = [{
label="Large"
control={<Radio />}
/>
<FormControlLabel
value="full"
label="Full"
control={<Radio />}
/>
</RadioGroup>
</FormControl>
<div className="u-mt-1">
Expand All @@ -283,6 +289,7 @@ const initialVariants = [{
{state.modalOpened && (
<DialogComponent
open
{...(variant.fullScreen && { fullScreen: true })}
size={DialogComponent !== ConfirmDialog ? state.size : undefined}
onClose={variant.withCloseButton ? handleClose : undefined}
onBack={variant.withBackButton ? handleBack : undefined}
Expand Down
2 changes: 1 addition & 1 deletion react/CozyDialogs/dialogPropTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types'

export default {
size: PropTypes.oneOf(['small', 'medium', 'large']),
size: PropTypes.oneOf(['small', 'medium', 'large', 'full']),
open: PropTypes.bool.isRequired,
disableTitleAutoPadding: PropTypes.bool,
background: PropTypes.string,
Expand Down
5 changes: 4 additions & 1 deletion react/CozyDialogs/useCozyDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useBreakpoints from '../providers/Breakpoints'
import { makeStyles } from '../styles'

let globalId = 0
const modalSizes = ['small', 'medium', 'large']
const modalSizes = ['small', 'medium', 'large', 'full']

const useStyles = makeStyles({
paper: {
Expand Down Expand Up @@ -92,19 +92,22 @@ const useCozyDialog = props => {

const dividerClassName = 'divider--dialog'
const dividerProps = {
...componentsProps?.divider,
classes: {
root: dividerClassName
}
}

const dialogActionsClassName = 'cozyDialogActions'
const dialogActionsProps = {
...componentsProps?.dialogActions,
classes: {
root: dialogActionsClassName
}
}

const dialogContentProps = {
...componentsProps?.dialogContent,
classes: {
root: cx({
disableGutters
Expand Down
4 changes: 4 additions & 0 deletions react/MuiCozyTheme/overrides/makeLightNormalOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ export const makeLightNormalOverrides = theme => ({
maxWidth: '800px'
}
},
'&.full': {
width: '100%',
maxWidth: '100%'
},
'&.overflow': {
overflowY: 'visible !important', // Allow the icon to overflow the dialog, otherwise it will be cut off,
'& .cozyDialogContent': {
Expand Down
59 changes: 56 additions & 3 deletions react/SearchBar/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,72 @@ import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
import Variants from 'cozy-ui/docs/components/Variants'
import SearchBar from 'cozy-ui/transpiled/react/SearchBar'
import Typography from 'cozy-ui/transpiled/react/Typography'
import CloudIcon from 'cozy-ui/transpiled/react/Icons/Cloud'
import FormControlLabel from 'cozy-ui/transpiled/react/FormControlLabel'
import RadioGroup from 'cozy-ui/transpiled/react/RadioGroup'
import Radio from 'cozy-ui/transpiled/react/Radios'
import FormControl from 'cozy-ui/transpiled/react/FormControl'
import FormLabel from 'cozy-ui/transpiled/react/FormLabel'

const initialVariants = [{ elevation: true }]
const initialVariants = [{ elevation: true, button: false, customIcon: false, disabledClear: false }]
initialState = { size: 'small' }

;

<DemoProvider>
<Variants initialVariants={initialVariants} screenshotAllVariants>
{variant => (
<>
<FormControl component="fieldset">
<FormLabel component="legend">Size</FormLabel>
<RadioGroup
aria-label="radio"
name="size"
row
value={state.size}
onChange={event => { setState({ size: event.target.value }) }}
>
<FormControlLabel
value="small"
label="Small"
control={<Radio />}
/>
<FormControlLabel
value="medium"
label="Medium"
control={<Radio />}
/>
<FormControlLabel
value="large"
label="Large"
control={<Radio />}
/>
<FormControlLabel
value="auto"
label="Auto"
control={<Radio />}
/>
</RadioGroup>
</FormControl>
<Typography className="u-mb-half">Normal</Typography>
<SearchBar className="u-mb-2" elevation={variant.elevation} />
<SearchBar className="u-mb-2"
elevation={variant.elevation}
size={state.size}
disabledClear={variant.disabledClear}
type={variant.button ? "button" : "search"}
icon={variant.customIcon ? CloudIcon : undefined}
label={variant.button ? <Typography color="primary">This is a label</Typography> : undefined}
/>
<Typography className="u-mb-half">Disabled</Typography>
<SearchBar elevation={variant.elevation} disabled />
<SearchBar
disabled
elevation={variant.elevation}
size={state.size}
disabledClear={variant.disabledClear}
type={variant.button ? "button" : "search"}
icon={variant.customIcon ? CloudIcon : undefined}
label={variant.button ? <Typography color="primary">This is a label</Typography> : undefined}
/>
</>
)}
</Variants>
Expand Down
Loading
Loading