cozy-ui 124.1.1 → 125.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "124.1.1",
3
+ "version": "125.0.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -16,10 +16,10 @@ import NotesIcon from '../Icons/Notes'
16
16
  import NotesTextIcon from '../Icons/NotesText'
17
17
  import PassIcon from '../Icons/Pass'
18
18
  import PassTextIcon from '../Icons/PassText'
19
- import StoreIcon from '../Icons/Store'
20
- import StoreTextIcon from '../Icons/StoreText'
21
19
  import PhotosIcon from '../Icons/Photos'
22
20
  import PhotosTextIcon from '../Icons/PhotosText'
21
+ import StoreIcon from '../Icons/Store'
22
+ import StoreTextIcon from '../Icons/StoreText'
23
23
  import TwakeTextIcon from '../Icons/TwakeText'
24
24
  import TwakeWorkplaceIcon from '../Icons/TwakeWorkplace'
25
25
  import WorkplaceTextIcon from '../Icons/WorkplaceText'
@@ -56,6 +56,13 @@ const useCozyDialog = props => {
56
56
  }`,
57
57
  scrollPaper: scrollPaperClassName
58
58
  },
59
+ BackdropProps: {
60
+ style: {
61
+ transitionDelay: 50,
62
+ ...otherProps?.BackdropProps?.style
63
+ },
64
+ ...otherProps.BackdropProps
65
+ },
59
66
  TransitionProps: {
60
67
  fullScreen,
61
68
  ...otherProps.TransitionProps
@@ -1,43 +1,119 @@
1
1
  import cx from 'classnames'
2
2
  import PropTypes from 'prop-types'
3
- import React, { Component } from 'react'
3
+ import React, { createContext, forwardRef, useContext, useMemo } from 'react'
4
4
 
5
5
  import styles from './styles.styl'
6
6
 
7
- export const Layout = ({ children, className, monoColumn, ...rest }) => {
7
+ export const LayoutContext = createContext()
8
+
9
+ export const useLayout = () => {
10
+ const context = useContext(LayoutContext)
11
+
12
+ if (!context) {
13
+ throw new Error('useLayout must be used within a LayoutContext')
14
+ }
15
+ return context
16
+ }
17
+
18
+ const LayoutProvider = React.memo(({ monoColumn, withTopBar, children }) => {
19
+ const value = useMemo(
20
+ () => ({
21
+ monoColumn,
22
+ withTopBar
23
+ }),
24
+ [monoColumn, withTopBar]
25
+ )
26
+
27
+ return (
28
+ <LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>
29
+ )
30
+ })
31
+
32
+ LayoutProvider.displayName = 'LayoutProvider'
33
+
34
+ export const Layout = forwardRef(
35
+ ({ children, className, monoColumn, withTopBar, ...props }, ref) => {
36
+ const variant = monoColumn ? 'monocolumn' : '2panes'
37
+
38
+ return (
39
+ <LayoutProvider monoColumn={monoColumn} withTopBar={withTopBar}>
40
+ <div
41
+ ref={ref}
42
+ className={cx(
43
+ className,
44
+ styles['o-layout'],
45
+ styles[`o-layout-${variant}`],
46
+ {
47
+ [styles[`o-layout-topbar`]]: withTopBar
48
+ }
49
+ )}
50
+ {...props}
51
+ >
52
+ {children}
53
+ </div>
54
+ </LayoutProvider>
55
+ )
56
+ }
57
+ )
58
+
59
+ Layout.displayName = 'Layout'
60
+
61
+ export const Main = forwardRef(({ className, children, ...props }, ref) => {
62
+ const { monoColumn, withTopBar } = useLayout()
63
+ const variant = monoColumn ? 'monocolumn' : '2panes'
64
+
65
+ return (
66
+ <main
67
+ ref={ref}
68
+ className={cx(
69
+ className,
70
+ styles['o-layout-main'],
71
+ styles[`o-layout-main-${variant}`],
72
+ {
73
+ [styles[`o-layout-main-${variant}--topbar`]]: withTopBar
74
+ }
75
+ )}
76
+ {...props}
77
+ >
78
+ {children}
79
+ </main>
80
+ )
81
+ })
82
+
83
+ Main.displayName = 'Main'
84
+
85
+ export const Content = forwardRef(({ className, children, ...props }, ref) => {
86
+ const { monoColumn } = useLayout()
87
+ const variant = monoColumn ? 'monocolumn' : '2panes'
88
+
8
89
  return (
9
90
  <div
91
+ role="main"
92
+ ref={ref}
10
93
  className={cx(
11
- monoColumn ? styles['o-layout'] : styles['o-layout-2panes'],
12
94
  className,
13
- [styles['o-layout--rounded']]
95
+ styles['o-layout-content'],
96
+ styles[`o-layout-content-${variant}`]
14
97
  )}
15
- {...rest}
98
+ {...props}
16
99
  >
17
100
  {children}
18
101
  </div>
19
102
  )
20
- }
21
-
22
- export const Main = ({ children, ...rest }) => <main {...rest}>{children}</main>
103
+ })
23
104
 
24
- export class Content extends Component {
25
- render() {
26
- const { children, ...rest } = this.props
27
- return (
28
- <div role="main" {...rest}>
29
- {children}
30
- </div>
31
- )
32
- }
33
- }
105
+ Content.displayName = 'Content'
34
106
 
35
107
  Layout.propTypes = {
36
108
  children: PropTypes.node,
37
109
  className: PropTypes.string,
110
+ /** Used to add/remove top spacing when using with or without a topbar */
111
+ withTopBar: PropTypes.bool,
112
+ /** Should be true if no sidebar in the app */
38
113
  monoColumn: PropTypes.bool
39
114
  }
40
115
 
41
116
  Layout.defaultProps = {
117
+ withTopBar: true,
42
118
  monoColumn: false
43
119
  }
@@ -34,6 +34,7 @@ import CheckIcon from 'cozy-ui/transpiled/react/Icons/Check'
34
34
  import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
35
35
  import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
36
36
  import { makeStyles } from 'cozy-ui/transpiled/react/styles'
37
+ import Variants from 'cozy-ui/docs/components/Variants'
37
38
 
38
39
  /**
39
40
  * In a normal app, ExampleRouterNavLink is from react-router
@@ -50,13 +51,6 @@ const ExampleRouterNavLink = ({ children, className, active, activeClassName, on
50
51
  const NavLink = genNavLink(ExampleRouterNavLink)
51
52
 
52
53
  // Not necessary in a normal app
53
- const styles = {
54
- layout: {
55
- position: 'relative',
56
- transform: 'translateZ(0)'
57
- }
58
- }
59
-
60
54
  const useStyles = makeStyles({
61
55
  layout: {
62
56
  position: 'relative',
@@ -67,12 +61,13 @@ const useStyles = makeStyles({
67
61
  }
68
62
  })
69
63
 
70
- ;
64
+ const initialVariants = [{ monoColumn: false, withTopBar: true }]
65
+ const [active, setActive] = useState(['Section 1', 'Subsection 1'])
66
+ const styles = useStyles()
71
67
 
72
- const Example = () => {
73
- const [active, setActive] = useState(['Section 1', 'Subsection 1'])
74
- const styles = useStyles()
68
+ ;
75
69
 
70
+ const SideBar = ({ variant }) => {
76
71
  // makeProps is not necessary in a normal app since react-router sets active
77
72
  // and onClick by itself
78
73
  const makeProps = route => {
@@ -80,7 +75,7 @@ const Example = () => {
80
75
  return { onClick: () => setActive(route), active: routeIsMatching }
81
76
  }
82
77
 
83
- return <Layout className={styles.layout}>
78
+ return (
84
79
  <Sidebar>
85
80
  <Nav>
86
81
  <NavItem>
@@ -114,53 +109,27 @@ const Example = () => {
114
109
  </NavItem>
115
110
  </Nav>
116
111
  </Sidebar>
117
- <Main>
118
- <Content className='u-p-1'>
119
- <h2 className='u-mt-0'>{ active.join(' / ') }</h2>
120
- { content.ada.short }
121
- </Content>
122
- </Main>
123
- </Layout>
112
+ )
124
113
  }
125
114
 
126
- <DemoProvider>
127
- <Example />
128
- </DemoProvider>
129
- ```
130
-
131
- `monoColumn` option (without sidebar)
132
-
133
- ```jsx
134
- import { Layout, Main, Content } from 'cozy-ui/transpiled/react/Layout'
135
- import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
136
- import { makeStyles } from 'cozy-ui/transpiled/react/styles'
137
-
138
- // Not necessary in a normal app
139
- const useStyles = makeStyles({
140
- layout: {
141
- '& > main': {
142
- minHeight: 'unset'
143
- }
144
- }
145
- })
146
-
147
- const Example = () => {
148
- const styles = useStyles()
149
-
150
- return (
151
- <Layout className={styles.layout} monoColumn>
115
+ <Variants initialVariants={initialVariants} screenshotAllVariants>
116
+ {variant => (
117
+ <DemoProvider>
118
+ <Layout
119
+ className={styles.layout}
120
+ withTopBar={variant.withTopBar}
121
+ monoColumn={variant.monoColumn}
122
+ >
123
+ {!variant.monoColumn && <SideBar variant={variant} />}
124
+ {variant.withTopBar && <div className="u-flex-m u-dn u-flex-items-center u-pos-absolute u-top-0 u-w-100" style={{ height: '48px', backgroundColor: 'var(--defaultBackgroundColor)' }}>Fake TopBar</div>}
152
125
  <Main>
153
126
  <Content className='u-p-1'>
127
+ <h2 className='u-mt-0'>{ active.join(' / ') }</h2>
154
128
  { content.ada.short }
155
129
  </Content>
156
130
  </Main>
157
- </Layout>
158
- )
159
- }
160
-
161
- ;
162
-
163
- <DemoProvider>
164
- <Example />
165
- </DemoProvider>
131
+ </Layout>
132
+ </DemoProvider>
133
+ )}
134
+ </Variants>
166
135
  ```
@@ -1,7 +1,10 @@
1
1
  @require '../../stylus/objects/layouts'
2
2
 
3
3
  .o-layout
4
- @extend $app
4
+ @extend $app-layout
5
5
 
6
- .o-layout-2panes
7
- @extend $app-2panes-sticky
6
+ .o-layout-main
7
+ @extend $app-main
8
+
9
+ .o-layout-content
10
+ @extend $app-content
@@ -29,11 +29,13 @@ const NavLink = genNavLink(
29
29
  <a className={cx(className, active ? activeClassName : null)}>{children}</a>
30
30
  )
31
31
  )
32
+
33
+ const demoStyle = { position: "initial" }
32
34
  // -->
33
35
 
34
36
  ;
35
37
 
36
- <Sidebar id='sidebar'>
38
+ <Sidebar id='sidebar' style={demoStyle}>
37
39
  <Nav>
38
40
  <NavItem id='nav-item'>
39
41
  <NavLink to="/warn" active>
@@ -25,11 +25,7 @@ const Sidebar = ({ children, className, ...restProps }) => {
25
25
  return (
26
26
  <aside
27
27
  id="sidebar"
28
- className={cx(
29
- styles['o-sidebar'],
30
- [styles['o-sidebar--large']],
31
- className
32
- )}
28
+ className={cx(styles['o-sidebar'], className)}
33
29
  {...restProps}
34
30
  >
35
31
  {children}
@@ -50,8 +50,7 @@ $elastic-content
50
50
  $elastic-bar
51
51
  flex 0 0 auto
52
52
 
53
- // One column layout
54
- $app
53
+ $app-layout
55
54
  box-sizing border-box
56
55
  display flex
57
56
  max-width 100%
@@ -60,83 +59,90 @@ $app
60
59
  background-color var(--paperBackgroundColor)
61
60
  color var(--primaryTextColor)
62
61
 
63
- main
64
- display flex
65
- flex-direction column
66
- flex 0 0 auto
67
-
68
- main,
69
- main > [role=contentinfo], // Deprecated
70
- main > [role=main]
71
- position relative
72
- display flex
73
- flex-direction column
74
- flex 1 1 auto
75
- box-sizing border-box
76
- height 100%
77
- overflow-x hidden
78
- overflow-y auto
79
-
80
- &--rounded
81
- +medium-screen('min') // desktop only
82
- main
83
- background-color var(--defaultBackgroundColor)
62
+ +medium-screen() // mobile + tablet
63
+ display block
84
64
 
85
- & > [role=main]
86
- margin 1rem 1rem 1rem 0
87
- border-radius 1rem
88
- background-color var(--paperBackgroundColor)
65
+ &-topbar
66
+ +medium-screen() // mobile + tablet
67
+ // this pseudo-element is "ghost" element replacing bar
68
+ &:before
69
+ content ''
70
+ display block
71
+ height barHeight
72
+
73
+ // When you want a sidebar
74
+ &-2panes
75
+ flex 0 0 100%
76
+ align-items stretch
77
+
78
+ +medium-screen() // mobile + tablet
79
+ // this pseudo-element is "ghost" element replacing nav
80
+ &:after
81
+ content ''
82
+ display block
83
+ height navHeight
84
+
85
+ $app-main
86
+ display flex
87
+ flex-direction column
88
+ position relative
89
+ flex 1 1 auto
90
+ box-sizing border-box
91
+ overflow-x hidden
92
+ overflow-y auto
89
93
 
90
94
  +medium-screen() // mobile + tablet
91
95
  display block
92
-
96
+ overflow visible
93
97
  // iPhone X environment tweak
94
- main
95
- padding-left env(safe-area-inset-left)
96
- padding-right env(safe-area-inset-right)
97
- padding-bottom env(safe-area-inset-bottom)
98
- min-height 'calc(100vh - var(--sidebarHeight) - %s)' % barHeight
99
-
100
- main,
101
- main > [role=contentinfo], // Deprecated
102
- main > [role=main]
103
- display block
104
- overflow visible
105
-
106
- // These pseudo-element are "ghost" elements replacing bar and nav
107
- &:before
108
- &:after
109
- content ''
110
- display block
111
-
112
- &:before
113
- height barHeight
114
-
115
- &:after
116
- height navHeight
117
-
118
- // STICKY layout
119
- // When you want a sidebar and you want it to act like a sticky footer on mobile
120
- $app-2panes-sticky
121
- @extend $app
122
- flex 0 0 100%
123
- align-items stretch
98
+ padding-left env(safe-area-inset-left)
99
+ padding-right env(safe-area-inset-right)
100
+ padding-bottom env(safe-area-inset-bottom)
101
+
102
+ &-monocolumn
103
+ height 100%
104
+
105
+ +medium-screen() // mobile + tablet
106
+ min-height 100vh
124
107
 
125
- & > aside
126
- display flex
127
- flex-direction column
128
- flex 0 0 auto
108
+ &--topbar
109
+ +medium-screen() // mobile + tablet
110
+ min-height 'calc(100vh - %s)' % barHeight
129
111
 
130
- main,
131
- main > [role=contentinfo], // Deprecated
132
- main > [role=main]
112
+ &-2panes
133
113
  height auto
114
+ background-color var(--defaultBackgroundColor)
115
+
116
+ +medium-screen() // mobile + tablet
117
+ min-height calc(100vh - var(--sidebarHeight))
118
+ background-color transparent
119
+
120
+ &--topbar
121
+ +medium-screen() // mobile + tablet
122
+ min-height 'calc(100vh - var(--sidebarHeight) - %s)' % barHeight
123
+
124
+ $app-content
125
+ position relative
126
+ display flex
127
+ flex-direction column
128
+ flex 1 1 auto
129
+ box-sizing border-box
130
+ overflow-x hidden
131
+ overflow-y auto
132
+ background-color var(--paperBackgroundColor)
134
133
 
135
134
  +medium-screen() // mobile + tablet
136
- > aside
137
- position fixed
138
- bottom 0
139
- left 0
140
- display block
141
- z-index var(--zIndex-nav)
142
- width 100%
135
+ display block
136
+ overflow visible
137
+
138
+ &-monocolumn
139
+ height 100%
140
+
141
+ &-2panes
142
+ height auto
143
+ margin 1rem 1rem 1rem 0
144
+ border-radius 1rem
145
+
146
+ +medium-screen() // mobile + tablet
147
+ margin 0
148
+ border-radius 0
@@ -9,22 +9,27 @@
9
9
  --sidebarHeight: rem(52)
10
10
 
11
11
  $sidebar
12
- width rem(220)
12
+ width rem(236)
13
13
  background-color var(--defaultBackgroundColor)
14
14
  overflow-y auto
15
15
  overflow-x hidden
16
+ display flex
17
+ flex-direction column
18
+ flex 0 0 auto
16
19
 
17
20
  &--border
18
21
  border-right rem(1) solid var(--dividerColor)
19
22
 
20
- &--large
21
- width rem(236)
22
-
23
23
  +medium-screen()
24
24
  justify-content space-between
25
25
  border 0
26
26
  border-top rem(1) solid var(--dividerColor)
27
27
  height var(--sidebarHeight)
28
28
  width 100%
29
+ position fixed
30
+ bottom 0
31
+ left 0
32
+ display block
33
+ z-index var(--zIndex-nav)
29
34
  // iPhone X environment tweak
30
35
  padding-bottom env(safe-area-inset-bottom)
@@ -24,10 +24,10 @@ import NotesIcon from "cozy-ui/transpiled/react/Icons/Notes";
24
24
  import NotesTextIcon from "cozy-ui/transpiled/react/Icons/NotesText";
25
25
  import PassIcon from "cozy-ui/transpiled/react/Icons/Pass";
26
26
  import PassTextIcon from "cozy-ui/transpiled/react/Icons/PassText";
27
- import StoreIcon from "cozy-ui/transpiled/react/Icons/Store";
28
- import StoreTextIcon from "cozy-ui/transpiled/react/Icons/StoreText";
29
27
  import PhotosIcon from "cozy-ui/transpiled/react/Icons/Photos";
30
28
  import PhotosTextIcon from "cozy-ui/transpiled/react/Icons/PhotosText";
29
+ import StoreIcon from "cozy-ui/transpiled/react/Icons/Store";
30
+ import StoreTextIcon from "cozy-ui/transpiled/react/Icons/StoreText";
31
31
  import TwakeTextIcon from "cozy-ui/transpiled/react/Icons/TwakeText";
32
32
  import TwakeWorkplaceIcon from "cozy-ui/transpiled/react/Icons/TwakeWorkplace";
33
33
  import WorkplaceTextIcon from "cozy-ui/transpiled/react/Icons/WorkplaceText";
@@ -24,7 +24,7 @@ var useStyles = makeStyles({
24
24
  });
25
25
 
26
26
  var useCozyDialog = function useCozyDialog(props) {
27
- var _componentsProps$dial, _componentsProps$dial2, _componentsProps$dial3;
27
+ var _otherProps$BackdropP, _componentsProps$dial, _componentsProps$dial2, _componentsProps$dial3;
28
28
 
29
29
  var size = props.size,
30
30
  actions = props.actions,
@@ -70,6 +70,11 @@ var useCozyDialog = function useCozyDialog(props) {
70
70
  paper: "".concat(paperClassName, " ").concat(styles.paper, " ").concat(otherProps.classes ? otherProps.classes.paper : ''),
71
71
  scrollPaper: scrollPaperClassName
72
72
  }),
73
+ BackdropProps: _objectSpread({
74
+ style: _objectSpread({
75
+ transitionDelay: 50
76
+ }, otherProps === null || otherProps === void 0 ? void 0 : (_otherProps$BackdropP = otherProps.BackdropProps) === null || _otherProps$BackdropP === void 0 ? void 0 : _otherProps$BackdropP.style)
77
+ }, otherProps.BackdropProps),
73
78
  TransitionProps: _objectSpread({
74
79
  fullScreen: fullScreen
75
80
  }, otherProps.TransitionProps)
@@ -1,28 +1,6 @@
1
- export function Layout({ children, className, monoColumn, ...rest }: {
2
- [x: string]: any;
3
- children: any;
4
- className: any;
5
- monoColumn: any;
6
- }): JSX.Element;
7
- export namespace Layout {
8
- namespace propTypes {
9
- const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
10
- const className: PropTypes.Requireable<string>;
11
- const monoColumn: PropTypes.Requireable<boolean>;
12
- }
13
- namespace defaultProps {
14
- const monoColumn_1: boolean;
15
- export { monoColumn_1 as monoColumn };
16
- }
17
- }
18
- export function Main({ children, ...rest }: {
19
- [x: string]: any;
20
- children: any;
21
- }): JSX.Element;
22
- export class Content extends React.Component<any, any, any> {
23
- constructor(props: Readonly<any>);
24
- constructor(props: any, context?: any);
25
- render(): JSX.Element;
26
- }
27
- import PropTypes from "prop-types";
1
+ export const LayoutContext: React.Context<any>;
2
+ export function useLayout(): any;
3
+ export const Layout: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
4
+ export const Main: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
5
+ export const Content: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
28
6
  import React from "react";