playbook_ui 14.11.1.pre.alpha.PLAY1751pbcontenttagpt25529 → 14.11.1.pre.alpha.PLAY17445539

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_drawer/_drawer.scss +154 -177
  3. data/app/pb_kits/playbook/pb_drawer/_drawer.tsx +162 -264
  4. data/app/pb_kits/playbook/pb_drawer/context.ts +11 -0
  5. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_behavior.jsx +38 -0
  6. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_borders.jsx +3 -45
  7. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_breakpoints.jsx +0 -1
  8. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_default.jsx +9 -16
  9. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.jsx +44 -19
  10. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.md +21 -3
  11. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_overlay.jsx +16 -21
  12. data/app/pb_kits/playbook/pb_drawer/docs/_drawer_sizes.jsx +2 -19
  13. data/app/pb_kits/playbook/pb_drawer/docs/example.yml +2 -1
  14. data/app/pb_kits/playbook/pb_drawer/docs/index.js +1 -0
  15. data/app/pb_kits/playbook/pb_drawer/drawer.test.jsx +5 -5
  16. data/app/pb_kits/playbook/pb_drawer/hooks/useBreakpoint.tsx +73 -0
  17. data/app/pb_kits/playbook/pb_drawer/hooks/useDrawerAnimation.tsx +21 -0
  18. data/app/pb_kits/playbook/pb_file_upload/file_upload.html.erb +6 -1
  19. data/app/pb_kits/playbook/pb_filter/filter.html.erb +5 -1
  20. data/app/pb_kits/playbook/pb_form_group/form_group.html.erb +6 -1
  21. data/app/pb_kits/playbook/pb_form_pill/form_pill.html.erb +1 -1
  22. data/dist/chunks/{_typeahead-TN5aDUj9.js → _typeahead-vFuUQM5F.js} +1 -1
  23. data/dist/chunks/_weekday_stacked-DG3A22sS.js +45 -0
  24. data/dist/chunks/vendor.js +1 -1
  25. data/dist/playbook-doc.js +1 -1
  26. data/dist/playbook-rails-react-bindings.js +1 -1
  27. data/dist/playbook-rails.js +1 -1
  28. data/dist/playbook.css +1 -1
  29. data/lib/playbook/version.rb +1 -1
  30. metadata +7 -3
  31. data/dist/chunks/_weekday_stacked-BcnpLG66.js +0 -45
@@ -9,8 +9,8 @@ const useDrawer = (visible = false) => {
9
9
  };
10
10
 
11
11
  const DrawerDefault = () => {
12
- const [headerSeparatorDrawerOpened, toggleHeaderSeparatorDrawer] = useDrawer();
13
- const [bothSeparatorsDrawerOpened, toggleBothSeparatorsDrawer] = useDrawer();
12
+ const [drawerLeftOpen, toggleDrawerLeftOpen] = useDrawer();
13
+ const [drawerRightOpen, toggleDrawerRightOpen ] = useDrawer();
14
14
 
15
15
  return (
16
16
  <>
@@ -18,13 +18,13 @@ const DrawerDefault = () => {
18
18
  <Button
19
19
  id="sm"
20
20
  marginRight="md"
21
- onClick={toggleHeaderSeparatorDrawer}
21
+ onClick={toggleDrawerLeftOpen}
22
22
  >
23
23
  {"Left Drawer"}
24
24
  </Button>
25
25
  <Button
26
26
  marginRight="xl"
27
- onClick={toggleBothSeparatorsDrawer}
27
+ onClick={toggleDrawerRightOpen}
28
28
  >
29
29
  {"Right Drawer"}
30
30
  </Button>
@@ -32,12 +32,8 @@ const DrawerDefault = () => {
32
32
  <Flex>
33
33
  {/* Left Drawer */}
34
34
  <Drawer
35
- behavior={"push"}
36
- fullHeight
37
- onClose={toggleHeaderSeparatorDrawer}
38
- opened={headerSeparatorDrawerOpened}
39
- overlay
40
- placement={"left"}
35
+ onClose={toggleDrawerLeftOpen}
36
+ opened={drawerLeftOpen}
41
37
  size={"lg"}
42
38
  >
43
39
  Test me (Left Drawer)
@@ -45,11 +41,8 @@ const DrawerDefault = () => {
45
41
 
46
42
  {/* Right Drawer */}
47
43
  <Drawer
48
- behavior={"push"}
49
- fullHeight
50
- onClose={toggleBothSeparatorsDrawer}
51
- opened={bothSeparatorsDrawerOpened}
52
- overlay
44
+ onClose={toggleDrawerRightOpen}
45
+ opened={drawerRightOpen}
53
46
  placement={"right"}
54
47
  size={"lg"}
55
48
  >
@@ -60,4 +53,4 @@ const DrawerDefault = () => {
60
53
  );
61
54
  };
62
55
 
63
- export default DrawerDefault;
56
+ export default DrawerDefault;
@@ -1,31 +1,56 @@
1
- import React from "react";
2
- import { Button, Drawer, Icon, Title } from "playbook-ui";
1
+ import React, { useState, useEffect } from "react"
2
+ import { Button, Drawer, Icon, Nav, NavItem } from "playbook-ui"
3
3
 
4
4
  const DrawerMenu = () => {
5
+ const [isSmallScreen, setIsSmallScreen] = useState(false)
6
+
7
+ useEffect(() => {
8
+ const mediaQuery = window.matchMedia("(max-width: 600px)")
9
+ setIsSmallScreen(mediaQuery.matches)
10
+ const handler = (e) => setIsSmallScreen(e.matches)
11
+ mediaQuery.addEventListener('change', handler)
12
+ return () => mediaQuery.removeEventListener('change', handler)
13
+ }, [])
5
14
 
6
15
  return (
7
- <>
8
- <Button id="menuButton"
9
- padding="sm"
16
+ <div>
17
+ <Button id='menuButton'
18
+ padding='xs'
10
19
  >
11
- <Icon icon="bars"
12
- size="3x"
20
+ <Icon icon='bars'
21
+ size='2x'
13
22
  />
14
23
  </Button>
15
24
  <Drawer
16
- behavior="push"
17
- closeBreakpoint="md"
18
- menuButtonID="menuButton"
19
- overlay={false}
20
- placement="left"
21
- size="lg"
25
+ breakpoint="md"
26
+ placement='bottom'
27
+ size='full'
28
+ triggerId='menuButton'
22
29
  withinElement
23
30
  >
24
- <Title paddingBottom="md">A really neat menu</Title>
25
- <Button text="This Button does nothing" />
31
+ <Nav
32
+ highlight={false}
33
+ link='#'
34
+ orientation={isSmallScreen ? 'vertical' : 'horizontal'}
35
+ padding={isSmallScreen ? 'none' : 'sm'}
36
+ >
37
+ <NavItem link='#'
38
+ text='About'
39
+ />
40
+ <NavItem active
41
+ link='#'
42
+ text='Case Studies'
43
+ />
44
+ <NavItem link='#'
45
+ text='Service'
46
+ />
47
+ <NavItem link='#'
48
+ text='Contacts'
49
+ />
50
+ </Nav>
26
51
  </Drawer>
27
- </>
28
- );
29
- };
52
+ </div>
53
+ )
54
+ }
30
55
 
31
- export default DrawerMenu;
56
+ export default DrawerMenu
@@ -1,6 +1,24 @@
1
- Our drawer kit can fulfill your responsive menu needs! Using the `closeBreakpoint` prop you can have the menu close on smaller screens like phones/tablets.
1
+ The Drawer component can be used to create responsive navigation menus and sidebars. It provides flexible options for controlling when and how the drawer appears based on screen size.
2
+
3
+ ### Within Element
4
+ The `withinElement` prop allows you to render the drawer within its parent container:
5
+ - The drawer will be positioned relative to its parent element
6
+ - Useful for creating nested navigation structures
7
+ - This must be used in conjunction with the `triggerId` prop
8
+
9
+ This provides a clean way to create responsive navigation patterns that adapt to different screen sizes while maintaining a consistent user experience.
10
+
11
+ ### Trigger Id
12
+ The `triggerId` prop allows you to connect an element to control the drawer:
13
+ - The specified element will toggle the drawer open/closed
14
+ - The element is automatically hidden when the drawer is opened via breakpoint
15
+ - The element reappears when the drawer is closed via breakpoint
16
+
17
+ ### Breakpoint
18
+ Use the `breakpoint` prop to control when the drawer automatically opens or closes based on screen size. For example, setting `breakpoint="md"` will:
19
+ - Close the drawer on screens smaller than the medium breakpoint (992px)
20
+ - Automatically open the drawer on screens larger than or equal to the medium breakpoint
21
+
2
22
 
3
- Set a menu button with the `menuButtonID` props. When the Drawer is open, the menu button will be hidden. But when your Brakpoint closes the drawer, you can toggle the Drawer open/close with your menu butotn.
4
23
 
5
- Also use the `withinElement` props to have the Drawer open within a specific element, instead of the default behavior of it taking up the entire screen size.
6
24
 
@@ -1,24 +1,25 @@
1
- import React, { useState } from "react";
2
- import { Button, Drawer, Flex } from "playbook-ui";
1
+ import React, { useState } from "react"
2
+ import { Button, Drawer, Flex } from "playbook-ui"
3
3
 
4
4
  const DrawerSizes = () => {
5
5
  // Individual state variables for each drawer size
6
- const [openedNoOverlayDrawer, setOpenedNoOverlayDrawer] = useState(false);
7
- const [openedOverlayDrawer, setOpenedOverlayDrawer] = useState(false);
6
+ const [openedNoOverlayDrawer, setOpenedNoOverlayDrawer] = useState(false)
7
+ const [openedOverlayDrawer, setOpenedOverlayDrawer] = useState(false)
8
8
 
9
9
  // Toggle functions for each drawer
10
- const toggleNoOverlayDrawer = () => setOpenedNoOverlayDrawer(!openedNoOverlayDrawer);
11
- const toggleOverlayDrawer = () => setOpenedOverlayDrawer(!openedOverlayDrawer);
10
+ const toggleNoOverlayDrawer = () =>
11
+ setOpenedNoOverlayDrawer(!openedNoOverlayDrawer)
12
+ const toggleOverlayDrawer = () => setOpenedOverlayDrawer(!openedOverlayDrawer)
12
13
 
13
14
  return (
14
15
  <>
15
16
  <Flex wrap>
16
- <Button marginRight="md"
17
+ <Button marginRight='md'
17
18
  onClick={toggleNoOverlayDrawer}
18
19
  >
19
20
  No Overlay Drawer
20
21
  </Button>
21
- <Button marginRight="md"
22
+ <Button marginRight='md'
22
23
  onClick={toggleOverlayDrawer}
23
24
  >
24
25
  Overlay Drawer
@@ -27,29 +28,23 @@ const DrawerSizes = () => {
27
28
 
28
29
  {/* Drawers for each size */}
29
30
  <Drawer
30
- behavior="push"
31
- fullHeight
32
31
  onClose={toggleNoOverlayDrawer}
33
32
  opened={openedNoOverlayDrawer}
34
33
  overlay={false}
35
- placement="right"
36
- size="lg"
34
+ size='lg'
37
35
  >
38
36
  This is a Drawer with no overlay
39
37
  </Drawer>
40
38
  <Drawer
41
- behavior="push"
42
- fullHeight
43
39
  onClose={toggleOverlayDrawer}
44
40
  opened={openedOverlayDrawer}
45
- overlay
46
- placement="right"
47
- size="lg"
41
+ placement='right'
42
+ size='lg'
48
43
  >
49
- This is a Drawer with an overlay
44
+ This is a Drawer with an overlay
50
45
  </Drawer>
51
46
  </>
52
- );
53
- };
47
+ )
48
+ }
54
49
 
55
- export default DrawerSizes;
50
+ export default DrawerSizes
@@ -19,7 +19,8 @@ const DrawerSizes = () => {
19
19
  return (
20
20
  <>
21
21
  <Flex wrap>
22
- <Button marginRight="md"
22
+ <Button
23
+ marginRight="md"
23
24
  onClick={toggleXsDrawer}
24
25
  >
25
26
  XS Drawer
@@ -48,11 +49,8 @@ const DrawerSizes = () => {
48
49
 
49
50
  {/* Drawers for each size */}
50
51
  <Drawer
51
- behavior="push"
52
- fullHeight
53
52
  onClose={toggleXsDrawer}
54
53
  opened={openedXsDrawer}
55
- overlay
56
54
  placement="right"
57
55
  size="xs"
58
56
  >
@@ -60,47 +58,32 @@ const DrawerSizes = () => {
60
58
  </Drawer>
61
59
 
62
60
  <Drawer
63
- behavior="push"
64
- fullHeight
65
61
  onClose={toggleSmDrawer}
66
62
  opened={openedSmDrawer}
67
- overlay
68
- placement="right"
69
63
  size="sm"
70
64
  >
71
65
  This is an SM Drawer
72
66
  </Drawer>
73
67
 
74
68
  <Drawer
75
- behavior="push"
76
- fullHeight
77
69
  onClose={toggleMdDrawer}
78
70
  opened={openedMdDrawer}
79
- overlay
80
71
  placement="right"
81
- size="md"
82
72
  >
83
73
  This is an MD Drawer
84
74
  </Drawer>
85
75
 
86
76
  <Drawer
87
- behavior="push"
88
- fullHeight
89
77
  onClose={toggleLgDrawer}
90
78
  opened={openedLgDrawer}
91
- overlay
92
- placement="right"
93
79
  size="lg"
94
80
  >
95
81
  This is an LG Drawer
96
82
  </Drawer>
97
83
 
98
84
  <Drawer
99
- behavior="push"
100
- fullHeight
101
85
  onClose={toggleXlDrawer}
102
86
  opened={openedXlDrawer}
103
- overlay
104
87
  placement="right"
105
88
  size="xl"
106
89
  >
@@ -6,7 +6,8 @@ examples:
6
6
 
7
7
  react:
8
8
  - drawer_default: Default
9
- - drawer_menu: Menu Behavior
9
+ - drawer_behavior: Push Behavior
10
+ - drawer_menu: Within Element
10
11
  - drawer_sizes: Sizes
11
12
  - drawer_overlay: Overlay
12
13
  - drawer_borders: Borders
@@ -4,3 +4,4 @@ export { default as DrawerOverlay } from './_drawer_overlay.jsx'
4
4
  export { default as DrawerBorders } from './_drawer_borders.jsx'
5
5
  export { default as DrawerBreakpoints } from './_drawer_breakpoints.jsx'
6
6
  export { default as DrawerMenu } from './_drawer_menu.jsx'
7
+ export { default as DrawerBehavior } from './_drawer_behavior.jsx'
@@ -39,7 +39,7 @@ test('renders with the right border class when border prop is right', async () =
39
39
  const container = document.getElementById('drawer-id');
40
40
  const drawer = container.querySelector('#drawer-id .pb_drawer');
41
41
 
42
- expect(drawer).toHaveClass('drawer_border_right');
42
+ expect(drawer).toHaveClass('drawer_border-right');
43
43
  });
44
44
 
45
45
  test('renders with the full border class when border prop is full', async () => {
@@ -51,7 +51,7 @@ test('renders with the full border class when border prop is full', async () =>
51
51
 
52
52
  const container = document.getElementById('drawer-id');
53
53
  const drawer = container.querySelector('#drawer-id .pb_drawer');
54
- expect(drawer).toHaveClass('drawer_border_full');
54
+ expect(drawer).toHaveClass('drawer_border-full');
55
55
  });
56
56
 
57
57
  test('does not have a border class when border prop is none', async () => {
@@ -63,9 +63,9 @@ test('does not have a border class when border prop is none', async () => {
63
63
 
64
64
  const container = document.getElementById('drawer-id');
65
65
  const drawer = container.querySelector('#drawer-id .pb_drawer');
66
- expect(drawer).not.toHaveClass('drawer_border_right');
67
- expect(drawer).not.toHaveClass('drawer_border_left');
68
- expect(drawer).not.toHaveClass('drawer_border_full');
66
+ expect(drawer).not.toHaveClass('drawer_border-right');
67
+ expect(drawer).not.toHaveClass('drawer_border-left');
68
+ expect(drawer).not.toHaveClass('drawer_border-full');
69
69
  });
70
70
 
71
71
  test('renders the correct size class for a large drawer', async () => {
@@ -0,0 +1,73 @@
1
+ import { useState, useEffect } from 'react'
2
+
3
+ export const breakpointValues = {
4
+ none: 0,
5
+ xs: 575,
6
+ sm: 768,
7
+ md: 992,
8
+ lg: 1200,
9
+ xl: 1400,
10
+ } as const
11
+
12
+ type BreakpointSize = keyof typeof breakpointValues
13
+
14
+ interface UseBreakpointProps {
15
+ openBreakpoint?: BreakpointSize
16
+ closeBreakpoint?: BreakpointSize
17
+ triggerId?: string
18
+ }
19
+
20
+ export const useBreakpoint = ({
21
+ openBreakpoint = 'none',
22
+ closeBreakpoint = 'none',
23
+ triggerId
24
+ }: UseBreakpointProps) => {
25
+ const [isOpenBreakpointOpen, setIsOpenBreakpointOpen] = useState(false)
26
+ const [isUserClosed, setIsUserClosed] = useState(false)
27
+
28
+ useEffect(() => {
29
+ if (openBreakpoint === 'none' && closeBreakpoint === 'none') return
30
+
31
+ const handleResize = () => {
32
+ const width = window.innerWidth
33
+
34
+ if (openBreakpoint !== 'none') {
35
+ const openBreakpointWidth = breakpointValues[openBreakpoint]
36
+ if (width >= openBreakpointWidth) {
37
+ setIsOpenBreakpointOpen(true)
38
+ } else {
39
+ setIsOpenBreakpointOpen(false)
40
+ setIsUserClosed(false)
41
+ }
42
+ }
43
+
44
+ if (closeBreakpoint !== 'none') {
45
+ const closeBreakpointWidth = breakpointValues[closeBreakpoint]
46
+ if (width < closeBreakpointWidth) {
47
+ setIsOpenBreakpointOpen(false)
48
+ } else {
49
+ setIsOpenBreakpointOpen(true)
50
+ }
51
+ }
52
+
53
+ // Handle menu button visibility
54
+ if (triggerId) {
55
+ const menuButton = document.getElementById(triggerId)
56
+ if (menuButton) {
57
+ menuButton.style.display = isOpenBreakpointOpen ? 'none' : ''
58
+ }
59
+ }
60
+ }
61
+
62
+ window.addEventListener('resize', handleResize)
63
+ handleResize()
64
+
65
+ return () => window.removeEventListener('resize', handleResize)
66
+ }, [openBreakpoint, closeBreakpoint, triggerId, isOpenBreakpointOpen])
67
+
68
+ return {
69
+ isOpenBreakpointOpen,
70
+ isUserClosed,
71
+ setIsUserClosed
72
+ }
73
+ }
@@ -0,0 +1,21 @@
1
+ import { useState, useEffect } from 'react'
2
+
3
+ export const useDrawerAnimation = (isOpen: boolean) => {
4
+ const [animationState, setAnimationState] = useState('')
5
+
6
+ useEffect(() => {
7
+ if (isOpen) {
8
+ setAnimationState('afterOpen')
9
+ } else if (!isOpen && animationState === 'afterOpen') {
10
+ setAnimationState('beforeClose')
11
+ setTimeout(() => {
12
+ setAnimationState('')
13
+ }, 200)
14
+ }
15
+ }, [isOpen])
16
+
17
+ return {
18
+ animationState,
19
+ isVisible: isOpen || animationState === 'beforeClose'
20
+ }
21
+ }
@@ -1,4 +1,9 @@
1
- <%= pb_content_tag(:div) do %>
1
+ <%= content_tag("div",
2
+ aria: object.aria,
3
+ class: object.classname,
4
+ data: object.data,
5
+ id: object.id,
6
+ **combined_html_options) do %>
2
7
  <%= pb_rails("form_group", props: {cursor: "pointer", full_width: object.full_width}) do %>
3
8
  <label
4
9
  for="upload-<%= object.id %>"
@@ -1,4 +1,8 @@
1
- <%= pb_content_tag(:div) do %>
1
+ <%= content_tag(:div,
2
+ id: object.id,
3
+ data: object.data,
4
+ class: object.classname,
5
+ **combined_html_options) do %>
2
6
  <%= object.wrapper do %>
3
7
  <%= pb_rails("flex", props: { orientation: "row", padding_right: "lg", vertical: "center" }) do %>
4
8
  <% if (object.template != "sort_only") %>
@@ -1,3 +1,8 @@
1
- <%= pb_content_tag(:div) do %>
1
+ <%= content_tag(:div,
2
+ aria: object.aria,
3
+ class: object.classname,
4
+ data: object.data,
5
+ id: object.id,
6
+ **combined_html_options) do %>
2
7
  <%= content.presence %>
3
8
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= pb_content_tag(:div, class: object.classname + object.size_class, tabindex: object.tabindex) do %>
1
+ <%= content_tag(:div, id: object.id, data: object.data, class: object.classname + object.size_class, tabindex: object.tabindex, **combined_html_options) do %>
2
2
  <% if object.name.present? %>
3
3
  <%= pb_rails("avatar", props: { name: object.name, image_url: object.avatar_url, size: "xxs" }) %>
4
4
  <% if object.truncate %>