playbook_ui 13.27.0.pre.alpha.testingcollapsible2912 → 13.27.0.pre.alpha.testingcollapsible2917

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 139239375cde8415b10b6381e0d294df8666584609ff6c16002aab7f8cb2d5fa
4
- data.tar.gz: 870ef281c575c7e7c752df452e3c368a197f0adfdbd9a7659259a7b713d4772d
3
+ metadata.gz: b12c7a464c2f34a42001f703bfb42df3f750da9574ab1163e059a4ce6b906f77
4
+ data.tar.gz: 8deca1276b0a8ae5c8d6a542e2a7e5362c1c3f7e206c4379b21d2cb48da0cb97
5
5
  SHA512:
6
- metadata.gz: 031cc99959af36b9584cf2a68cd7e0dd69fa59908292e5c7865d9d44329ca6955c1968fa3000b724aef7e6416fcb67f08a3dea5542a88d99234e0d79176b0345
7
- data.tar.gz: 6614ed6e1c90b0d1c9e404952b1ef22759bd710389a156e821c796b550fca8bcb680615ddb2ee723ab7dc1f0a6c48af5ebfb5c43f58c7b67ce073a4c48defb5c
6
+ metadata.gz: 3d5187d01379e3fdc8aea8d2d0c6bdf717ba10ee4c60f29ca5eb4abb83900ddb5b78fd627522ec54aa1e3bb6957f36252dc9001827efd3b70bc597ee69cb6e10
7
+ data.tar.gz: 0e33d8a8583c2ad4c58002c04f087dae84ffa6586f8579eae2f1bd479cf4ab6143907a3305503e1679e179f98e4ac75a67069ce9b42056c2a84881de2149cab0
@@ -9,6 +9,7 @@ import CollapsibleContent from './child_kits/CollapsibleContent'
9
9
  import CollapsibleMain from './child_kits/CollapsibleMain'
10
10
  import CollapsibleContext from './context'
11
11
  import { IconSizes } from "../pb_icon/_icon"
12
+ import CollapsibleIcon from './child_kits/CollapsibleIcon'
12
13
 
13
14
 
14
15
  type CollapsibleProps = {
@@ -98,5 +99,6 @@ const Collapsible = ({
98
99
 
99
100
  Collapsible.Main = CollapsibleMain
100
101
  Collapsible.Content = CollapsibleContent
102
+ Collapsible.Icon = CollapsibleIcon
101
103
 
102
104
  export default Collapsible
@@ -0,0 +1,92 @@
1
+ import React from "react";
2
+ import Icon, { IconSizes } from "../../pb_icon/_icon";
3
+
4
+ type IconColors =
5
+ | "default"
6
+ | "light"
7
+ | "lighter"
8
+ | "link"
9
+ | "error"
10
+ | "success";
11
+
12
+ type IconProps = {
13
+ collapsed: boolean | (() => void);
14
+ icon?: string[] | string;
15
+ iconColor?: IconColors;
16
+ iconSize?: IconSizes;
17
+ onIconClick?: () => void;
18
+ };
19
+
20
+ type colorMap = {
21
+ default: string;
22
+ light: string;
23
+ lighter: string;
24
+ link: string;
25
+ error: string;
26
+ success: string;
27
+ };
28
+
29
+ const colorMap = {
30
+ default: "#242B42",
31
+ light: "#687887",
32
+ lighter: "#C1CDD6",
33
+ link: "#0056CF",
34
+ error: "#FF2229",
35
+ success: "#00CA74",
36
+ };
37
+
38
+ const CollapsibleIcon = ({
39
+ collapsed,
40
+ icon,
41
+ iconSize,
42
+ iconColor,
43
+ onIconClick,
44
+ }: IconProps) => {
45
+ const color = colorMap[iconColor];
46
+
47
+ const showIcon = (icon: string | string[]) => {
48
+ if (typeof icon === "string") {
49
+ return [icon, icon];
50
+ }
51
+ return icon;
52
+ };
53
+
54
+ const handleIconClick = (e: React.MouseEvent<HTMLElement>) => {
55
+ if (onIconClick) {
56
+ e.stopPropagation();
57
+ onIconClick();
58
+ }
59
+ };
60
+
61
+ return (
62
+ <>
63
+ {collapsed ? (
64
+ <div
65
+ className="icon_wrapper"
66
+ key={icon ? showIcon(icon)[0] : "chevron-down"}
67
+ onClick={(e) => handleIconClick(e)}
68
+ style={{ verticalAlign: "middle", color: color }}
69
+ >
70
+ <Icon
71
+ icon={icon ? showIcon(icon)[0] : "chevron-down"}
72
+ size={iconSize}
73
+ />
74
+ </div>
75
+ ) : (
76
+ <div
77
+ className="icon_wrapper"
78
+ key={icon ? showIcon(icon)[1] : "chevron-up"}
79
+ onClick={(e) => handleIconClick(e)}
80
+ style={{ verticalAlign: "middle", color: color }}
81
+ >
82
+ <Icon
83
+ icon={icon ? showIcon(icon)[1] : "chevron-up"}
84
+ size={iconSize}
85
+ />
86
+ </div>
87
+ )}
88
+ </>
89
+ );
90
+ };
91
+
92
+ export default CollapsibleIcon;
@@ -7,27 +7,9 @@ import { globalProps } from '../../utilities/globalProps'
7
7
 
8
8
  import Flex from '../../pb_flex/_flex'
9
9
  import FlexItem from '../../pb_flex/_flex_item'
10
- import Icon, { IconSizes } from "../../pb_icon/_icon"
10
+ import { IconSizes } from "../../pb_icon/_icon"
11
11
  import CollapsibleContext from '../context'
12
-
13
-
14
- type colorMap = {
15
- default: string,
16
- light: string,
17
- lighter: string,
18
- link: string,
19
- error: string,
20
- success: string
21
- }
22
-
23
- const colorMap = {
24
- default: "#242B42",
25
- light: "#687887",
26
- lighter: "#C1CDD6",
27
- link: "#0056CF",
28
- error: "#FF2229",
29
- success: "#00CA74",
30
- }
12
+ import CollapsibleIcon from './CollapsibleIcon'
31
13
 
32
14
  type CollapsibleMainProps = {
33
15
  children: React.ReactNode[] | React.ReactNode,
@@ -38,60 +20,6 @@ type CollapsibleMainProps = {
38
20
  }
39
21
  type IconColors = "default" | "light" | "lighter" | "link" | "error" | "success"
40
22
 
41
- type IconProps = {
42
- collapsed: boolean | (()=> void)
43
- icon?: string[] | string
44
- iconColor?: IconColors
45
- iconSize?: IconSizes
46
- onIconClick?: ()=> void
47
- }
48
-
49
- const ToggleIcon = ({ collapsed, icon, iconSize, iconColor, onIconClick }: IconProps) => {
50
- const color = colorMap[iconColor]
51
-
52
- const showIcon = (icon: string |string[]) => {
53
- if (typeof icon === "string") {
54
- return [icon, icon]
55
- }
56
- return icon
57
- }
58
-
59
- const handleIconClick = (e: React.MouseEvent<HTMLElement>) => {
60
- if (onIconClick) {
61
- e.stopPropagation();
62
- onIconClick()
63
- }
64
- }
65
-
66
- return (
67
- <>
68
- {collapsed ? (
69
- <div
70
- className="icon_wrapper"
71
- key={icon ? showIcon(icon)[0] : "chevron-down"}
72
- onClick={(e)=> handleIconClick(e)}
73
- style={{ verticalAlign: "middle", color: color }}
74
- >
75
- <Icon icon={icon ? showIcon(icon)[0] : "chevron-down"}
76
- size={iconSize}
77
- />
78
- </div>
79
- ) : (
80
- <div
81
- className="icon_wrapper"
82
- key={icon ? showIcon(icon)[1] : "chevron-up"}
83
- onClick={(e)=> handleIconClick(e)}
84
- style={{ verticalAlign: "middle", color: color }}
85
- >
86
- <Icon icon={icon ? showIcon(icon)[1] : "chevron-up"}
87
- size={iconSize}
88
- />
89
- </div>
90
- )}
91
- </>
92
- );
93
- }
94
-
95
23
  const CollapsibleMain = ({
96
24
  children,
97
25
  className,
@@ -120,7 +48,7 @@ const CollapsibleMain = ({
120
48
  >
121
49
  <FlexItem>{children}</FlexItem>
122
50
  <FlexItem>
123
- <ToggleIcon
51
+ <CollapsibleIcon
124
52
  collapsed={collapsed as () => void}
125
53
  icon={icon as string[] | string}
126
54
  iconColor={iconColor as IconColors}
@@ -0,0 +1,15 @@
1
+ <%= content_tag(:div,
2
+ id: object.id,
3
+ data: object.data,
4
+ class: object.classname,
5
+ aria: object.aria,
6
+ style: "color: #{object.icon_color};",
7
+ **combined_html_options) do %>
8
+ <% if object.icon.present? %>
9
+ <%= pb_rails("icon", props: { icon: object.show_icon(object.icon)[0], id:"collapsible_open_icon", size: object.size }) %>
10
+ <%= pb_rails("icon", props: { icon: object.show_icon(object.icon)[1], id:"collapsible_close_icon", size: object.size }) %>
11
+ <% else %>
12
+ <%= pb_rails("icon", props: { icon: "chevron-down", id:"collapsible_open_icon", size: object.size }) %>
13
+ <%= pb_rails("icon", props: { icon: "chevron-up", id:"collapsible_close_icon", size: object.size }) %>
14
+ <% end %>
15
+ <% end %>
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Playbook
4
+ module PbCollapsible
5
+ class CollapsibleIcon < Playbook::KitBase
6
+ prop :collapsed, type: Playbook::Props::Boolean,
7
+ default: true
8
+ prop :color, type: Playbook::Props::Enum,
9
+ values: %w[default light lighter link success error],
10
+ default: "default"
11
+ prop :icon
12
+ prop :size, type: Playbook::Props::Enum,
13
+ values: ["lg", "xs", "sm", "1x", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x", nil],
14
+ default: nil
15
+
16
+ def classname
17
+ generate_classname("pb_collapsible_icon_kit", separator: " ")
18
+ end
19
+
20
+ def show_icon(icon)
21
+ case icon
22
+ when ::String
23
+ [icon, icon]
24
+ when ::Array
25
+ icon
26
+ end
27
+ end
28
+
29
+ def icon_color
30
+ return "" if color.nil?
31
+
32
+ color_object = { light: "#687887", lighter: "#C1CDD6", link: "#0056CF", success: "#00CA74", error: "#FF2229", default: "#242B42" }
33
+ color_object[color.to_sym]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { Collapsible, useCollapsible, Background, Flex, Title, IconCircle, List, ListItem } from '../..'
2
+ import { Collapsible, useCollapsible, Background, Flex, Title, List, ListItem } from '../..'
3
3
 
4
4
  const CollapsibleCustomMain = () => {
5
5
  const [isCollapsed, setIsCollapsed] = useCollapsible(true)
@@ -25,10 +25,7 @@ const CollapsibleCustomMain = () => {
25
25
  size={4}
26
26
  text="Custom Main Section"
27
27
  />
28
- <IconCircle
29
- icon="check"
30
- size="xs"
31
- />
28
+ <Collapsible.Icon collapsed={isCollapsed}/>
32
29
  </Flex>
33
30
  </Background>
34
31
  <Collapsible.Content padding="none">
@@ -0,0 +1,5 @@
1
+ A custom Main section can also be used in place of the provided `Collapsible.Main`. This gives devs full control over that subcomponent. For example, here we are using global props to make that custom Main 'sticky' on scroll.
2
+
3
+ If a custom component is used in place of the default, devs must handle collapsible toggling themselves via the useCollapsible hook as seen in this example.
4
+
5
+ The default Collapsible icon can also be used as part of the custom Main as shown, you will need to pass the Collapsible state to the `collapsed` prop on the optional `Collapsible.Icon`.
@@ -2,10 +2,7 @@
2
2
  <%= pb_rails("background", props: { background_color: "white", position: "sticky", top: "0", cursor:"pointer", data: {"collapsible-main": "true"} }) do %>
3
3
  <%= pb_rails("flex", props: {align:"center", gap:"sm", justify:"between"}) do %>
4
4
  <%= pb_rails("title", props: { text: "Custom Main Section", tag: "h4", size: 4 }) %>
5
- <%= pb_rails("icon_circle", props: {
6
- icon: "check",
7
- size: "xs"
8
- }) %>
5
+ <%= pb_rails("collapsible/collapsible_icon") %>
9
6
  <% end %>
10
7
  <% end %>
11
8
  <%= pb_rails("flex", props: { align: "center", justify: "between" }) do %>
@@ -0,0 +1,5 @@
1
+ A custom Main section can also be used in place of the provided `collapsible/collapsible_main`. This gives devs full control over that subcomponent. For example, here we are using global props to make that custom Main 'sticky' on scroll.
2
+
3
+ If a custom component is used in place of the default, devs must add `data: {"collapsible-main": "true"}` to the custom Main for toggling of the collapsible to work correctly.
4
+
5
+ The default Collapsible icon can also be used as part of the custom Main as shown with the optional `collapsible/collapsible_icon`. This optional subcomponent accepts all icon related props `color`, `icon` and `size`.
@@ -7,7 +7,7 @@ examples:
7
7
  - collapsible_icons: Custom Icons
8
8
  - collapsible_external_controls: Toggle Collapsible With External Controls
9
9
  - collapsible_external_controls_multiple: Toggle All Collapsibles With One Control
10
- - collapsible_custom_main: Custom Main
10
+ - collapsible_custom_main_rails: Custom Main Section
11
11
 
12
12
  react:
13
13
  - collapsible_default: Default
@@ -15,7 +15,7 @@ examples:
15
15
  - collapsible_color: Icon Color
16
16
  - collapsible_icons: Custom Icons
17
17
  - collapsible_state: useCollapsible Hook
18
- - collapsible_custom_main: Custom Main
18
+ - collapsible_custom_main: Custom Main Section
19
19
 
20
20
 
21
21
  swift: