playbook_ui 13.19.0 → 13.20.0.pre.alpha.PLAY12572402
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/index.js +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/Components/CollapsibleTrail.tsx +6 -1
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableBody.tsx +2 -0
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +2 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +45 -0
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +7 -4
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_collapsible_trail.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_loading.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_subrow_headers.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_table_options.md +1 -1
- data/app/pb_kits/playbook/pb_date/docs/_date_alignment_swift.md +26 -6
- data/app/pb_kits/playbook/pb_date/docs/_date_default_swift.md +27 -8
- data/app/pb_kits/playbook/pb_icon/_icon.tsx +28 -16
- data/app/pb_kits/playbook/pb_icon/docs/_icon_custom.html.erb +5 -11
- data/app/pb_kits/playbook/pb_icon/docs/_icon_custom.jsx +44 -18
- data/app/pb_kits/playbook/pb_icon/docs/_icon_custom.md +4 -8
- data/app/pb_kits/playbook/pb_icon/icon.html.erb +6 -4
- data/app/pb_kits/playbook/pb_icon/icon.rb +27 -10
- data/app/pb_kits/playbook/pb_message/docs/_description.md +1 -1
- data/app/pb_kits/playbook/pb_nav/_subtle_mixin.scss +4 -0
- data/app/pb_kits/playbook/pb_table/_table.tsx +99 -67
- data/app/pb_kits/playbook/pb_table/docs/_table_div.html.erb +34 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_div.jsx +47 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_side_highlight.jsx +24 -25
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents.jsx +47 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents.md +7 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_as_divs.html.erb +34 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_as_divs.jsx +48 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_as_divs.md +3 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_rails.html.erb +34 -0
- data/app/pb_kits/playbook/pb_table/docs/_table_with_subcomponents_rails.md +7 -0
- data/app/pb_kits/playbook/pb_table/docs/example.yml +6 -0
- data/app/pb_kits/playbook/pb_table/docs/index.js +3 -0
- data/app/pb_kits/playbook/pb_table/styles/_content.scss +3 -3
- data/app/pb_kits/playbook/pb_table/styles/_desktop_collapse.scss +15 -15
- data/app/pb_kits/playbook/pb_table/styles/_headers.scss +3 -3
- data/app/pb_kits/playbook/pb_table/styles/_hover.scss +11 -11
- data/app/pb_kits/playbook/pb_table/styles/_mobile.scss +15 -15
- data/app/pb_kits/playbook/pb_table/styles/_mobile_collapse.scss +15 -15
- data/app/pb_kits/playbook/pb_table/styles/_reset.scss +3 -3
- data/app/pb_kits/playbook/pb_table/styles/_side_highlight.scss +2 -2
- data/app/pb_kits/playbook/pb_table/styles/_single-line.scss +4 -4
- data/app/pb_kits/playbook/pb_table/styles/_sticky_header.scss +2 -2
- data/app/pb_kits/playbook/pb_table/styles/_striped.scss +4 -4
- data/app/pb_kits/playbook/pb_table/styles/_structure.scss +22 -8
- data/app/pb_kits/playbook/pb_table/styles/_table-card.scss +7 -7
- data/app/pb_kits/playbook/pb_table/styles/_table-dark.scss +14 -14
- data/app/pb_kits/playbook/pb_table/styles/_table_header.scss +2 -2
- data/app/pb_kits/playbook/pb_table/styles/_tablet_collapse.scss +15 -15
- data/app/pb_kits/playbook/pb_table/styles/_vertical_border.scss +3 -4
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_body.tsx +64 -0
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_cell.tsx +66 -0
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_head.tsx +64 -0
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_header.tsx +66 -0
- data/app/pb_kits/playbook/pb_table/subcomponents/_table_row.tsx +74 -0
- data/app/pb_kits/playbook/pb_table/subcomponents/index.tsx +5 -0
- data/app/pb_kits/playbook/pb_table/table.html.erb +12 -2
- data/app/pb_kits/playbook/pb_table/table.rb +3 -0
- data/app/pb_kits/playbook/pb_table/table.test.js +142 -1
- data/app/pb_kits/playbook/pb_table/table_body.html.erb +17 -0
- data/app/pb_kits/playbook/pb_table/table_body.rb +15 -0
- data/app/pb_kits/playbook/pb_table/table_cell.html.erb +17 -0
- data/app/pb_kits/playbook/pb_table/table_cell.rb +17 -0
- data/app/pb_kits/playbook/pb_table/table_head.html.erb +17 -0
- data/app/pb_kits/playbook/pb_table/table_head.rb +15 -0
- data/app/pb_kits/playbook/pb_table/table_header.html.erb +49 -39
- data/app/pb_kits/playbook/pb_table/table_header.rb +8 -1
- data/app/pb_kits/playbook/pb_table/table_row.html.erb +17 -7
- data/app/pb_kits/playbook/pb_table/table_row.rb +8 -1
- data/app/pb_kits/playbook/pb_text_input/_text_input.tsx +9 -5
- data/app/pb_kits/playbook/pb_text_input/docs/_text_input_add_on.jsx +20 -0
- data/app/pb_kits/playbook/pb_user/docs/_user_presence_indicator_swift.md +30 -0
- data/app/pb_kits/playbook/pb_user/docs/_user_props_table.md +2 -1
- data/app/pb_kits/playbook/pb_user/docs/example.yml +1 -0
- data/app/pb_kits/playbook/utilities/_positioning.scss +48 -7
- data/app/pb_kits/playbook/utilities/globalProps.ts +23 -1
- data/dist/playbook-rails.js +6 -6
- data/lib/playbook/bottom.rb +33 -0
- data/lib/playbook/classnames.rb +4 -0
- data/lib/playbook/kit_base.rb +8 -0
- data/lib/playbook/left.rb +33 -0
- data/lib/playbook/right.rb +33 -0
- data/lib/playbook/top.rb +33 -0
- data/lib/playbook/version.rb +2 -2
- metadata +32 -7
- data/app/pb_kits/playbook/pb_table/_table_row.tsx +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb6d3b38a06890fb4242896896403e642f363c6a220d7483b366c26289aab8cd
|
4
|
+
data.tar.gz: ce847f1594dc3eb1ba9e142bafc7cca62bb8ab750a80df5e07962eb7dd6f0c3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00d36dc613747a14e0796cf9ea2d52ce59305ba50c509b28620766ba4b4e0060150bd45efa77a9ebe61cf220acb0d7501ce470a8ecbc42edf8a6cc47fab930f8
|
7
|
+
data.tar.gz: c1937c7a96b2f26b583798205223b98d1117236fa94ea764408e01896e5981700216e873fd466f76efc8cd842479d7afadc6c0a20deb10bae7235e74f3edc784
|
@@ -93,7 +93,7 @@ export { default as StarRating } from './pb_star_rating/_star_rating'
|
|
93
93
|
export { default as StatChange } from './pb_stat_change/_stat_change'
|
94
94
|
export { default as StatValue } from './pb_stat_value/_stat_value'
|
95
95
|
export { default as Table } from './pb_table/_table'
|
96
|
-
export { default as TableRow } from './pb_table/_table_row'
|
96
|
+
export { default as TableRow } from './pb_table/subcomponents/_table_row'
|
97
97
|
export { default as TextInput } from './pb_text_input/_text_input'
|
98
98
|
export { default as Textarea } from './pb_textarea/_textarea'
|
99
99
|
export { default as Time } from './pb_time/_time'
|
@@ -11,7 +11,12 @@ const CollapsibleTrail = ({ leftOffset }: { leftOffset: number }) => {
|
|
11
11
|
backgroundColor: "#E4E8F0",
|
12
12
|
}
|
13
13
|
|
14
|
-
return
|
14
|
+
return (
|
15
|
+
<div
|
16
|
+
className="collapsible-trail"
|
17
|
+
style={style}
|
18
|
+
/>
|
19
|
+
)
|
15
20
|
}
|
16
21
|
|
17
22
|
// Updated function to render multiple trails depending on depth
|
@@ -15,6 +15,7 @@ import { DataType } from "../Utilities/types"
|
|
15
15
|
type TableBodyProps = {
|
16
16
|
className?: string;
|
17
17
|
collapsibleTrail?: boolean
|
18
|
+
dark?: boolean,
|
18
19
|
id?: string;
|
19
20
|
subRowHeaders?: string[]
|
20
21
|
}
|
@@ -22,6 +23,7 @@ type TableBodyProps = {
|
|
22
23
|
export const TableBody = ({
|
23
24
|
className,
|
24
25
|
collapsibleTrail = true,
|
26
|
+
dark = false,
|
25
27
|
id,
|
26
28
|
subRowHeaders,
|
27
29
|
...props
|
@@ -10,6 +10,7 @@ import { DataType } from "../Utilities/types"
|
|
10
10
|
type TableHeaderProps = {
|
11
11
|
children?: React.ReactNode | React.ReactNode[]
|
12
12
|
className?: string
|
13
|
+
dark?: boolean,
|
13
14
|
enableSorting?: boolean
|
14
15
|
id?: string;
|
15
16
|
sortIcon?: string | string[]
|
@@ -18,6 +19,7 @@ type TableHeaderProps = {
|
|
18
19
|
export const TableHeader = ({
|
19
20
|
children,
|
20
21
|
className,
|
22
|
+
dark = false,
|
21
23
|
enableSorting = false,
|
22
24
|
id,
|
23
25
|
sortIcon = ["arrow-up-short-wide", "arrow-down-short-wide"],
|
@@ -95,4 +95,49 @@
|
|
95
95
|
border-right: $transparent !important;
|
96
96
|
}
|
97
97
|
}
|
98
|
+
|
99
|
+
&.dark {
|
100
|
+
.bg-white {
|
101
|
+
background: $bg_dark_card;
|
102
|
+
}
|
103
|
+
|
104
|
+
.bg-silver {
|
105
|
+
background: $bg_dark;
|
106
|
+
}
|
107
|
+
|
108
|
+
.table-header-cells:first-child, td:first-child {
|
109
|
+
box-shadow: 1px 0px 0px 0px $border_dark !important;
|
110
|
+
}
|
111
|
+
|
112
|
+
.collapsible-trail {
|
113
|
+
background-color: $border_dark !important;
|
114
|
+
}
|
115
|
+
|
116
|
+
.sort-button-icon, .header-sort-button > div {
|
117
|
+
color: $white !important;
|
118
|
+
}
|
119
|
+
|
120
|
+
.gray-icon {
|
121
|
+
color: $text_dk_light !important;
|
122
|
+
}
|
123
|
+
|
124
|
+
.sticky-header {
|
125
|
+
background-color: $bg_dark_card;
|
126
|
+
}
|
127
|
+
|
128
|
+
.loading-toggle-icon,
|
129
|
+
.loading-cell {
|
130
|
+
&::after {
|
131
|
+
background-color: $bg_dark !important;
|
132
|
+
background-image: linear-gradient(
|
133
|
+
to left,
|
134
|
+
$bg_dark 0%,
|
135
|
+
lighten($bg_dark, 1%) 50%,
|
136
|
+
lighten($bg_dark, 2%) 60%,
|
137
|
+
$bg_dark 80%,
|
138
|
+
$bg_dark 100%
|
139
|
+
) !important;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
98
143
|
}
|
@@ -20,13 +20,14 @@ import AdvancedTableContext from "./Context/AdvancedTableContext";
|
|
20
20
|
import { TableHeader } from "./SubKits/TableHeader";
|
21
21
|
import { TableBody } from "./SubKits/TableBody";
|
22
22
|
|
23
|
-
import { DataType
|
23
|
+
import { DataType } from "./Utilities/types";
|
24
24
|
|
25
25
|
type AdvancedTableProps = {
|
26
26
|
aria?: { [key: string]: string };
|
27
27
|
children?: React.ReactNode | React.ReactNode[];
|
28
28
|
className?: string;
|
29
29
|
columnDefinitions: DataType[];
|
30
|
+
dark?: boolean,
|
30
31
|
data?: { [key: string]: string };
|
31
32
|
enableToggleExpansion?: "all" | "header" | "none";
|
32
33
|
expandedControl?: DataType;
|
@@ -50,6 +51,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
50
51
|
children,
|
51
52
|
className,
|
52
53
|
columnDefinitions,
|
54
|
+
dark = false,
|
53
55
|
data = {},
|
54
56
|
enableToggleExpansion = "header",
|
55
57
|
expandedControl,
|
@@ -80,7 +82,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
80
82
|
? expandedControl.onChange
|
81
83
|
: setLocalExpanded;
|
82
84
|
|
83
|
-
const columnHelper = createColumnHelper
|
85
|
+
const columnHelper = createColumnHelper();
|
84
86
|
|
85
87
|
//Create cells for first columns
|
86
88
|
const createCellFunction = (cellAccessors: string[]) => {
|
@@ -163,7 +165,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
163
165
|
data: loading ? Array(loadingStateRowCount).fill({}) : tableData,
|
164
166
|
columns,
|
165
167
|
onExpandedChange: setExpanded,
|
166
|
-
getSubRows: (row) => row.children,
|
168
|
+
getSubRows: (row: DataType) => row.children,
|
167
169
|
getCoreRowModel: getCoreRowModel(),
|
168
170
|
getExpandedRowModel: getExpandedRowModel(),
|
169
171
|
getSortedRowModel: getSortedRowModel(),
|
@@ -192,7 +194,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
192
194
|
const handleExpandOrCollapse = (row: Row<DataType>) => {
|
193
195
|
onToggleExpansionClick && onToggleExpansionClick(row);
|
194
196
|
|
195
|
-
const expandedState = expanded
|
197
|
+
const expandedState = expanded;
|
196
198
|
const targetParent = row?.parentId;
|
197
199
|
return setExpanded(
|
198
200
|
updateExpandAndCollapseState(tableRows, expandedState, targetParent)
|
@@ -231,6 +233,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
231
233
|
>
|
232
234
|
<Table
|
233
235
|
className={`${loading ? "content-loading" : ""}`}
|
236
|
+
dark={dark}
|
234
237
|
dataTable
|
235
238
|
numberSpacing="tabular"
|
236
239
|
responsive="none"
|
@@ -1 +1 @@
|
|
1
|
-
`collapsibleTrail` is an optional prop that is set to 'true' by default. If set to 'false', it will remove the trail on the left of rows when subRows are toggled open.
|
1
|
+
`collapsibleTrail` is an optional prop that is set to 'true' by default. If set to 'false', it will remove the trail on the left of the rows when subRows are toggled open.
|
@@ -8,7 +8,7 @@ For a visual of the data structure needed for `tableData`, see [here](https://gi
|
|
8
8
|
|
9
9
|
### columnDefinitions
|
10
10
|
|
11
|
-
`columnDefinitions` maps to the columns prop on the Tanstack table. Column definitions are the single most important part of building a table as they are responsible for building the underlying data model that is used for all sorting, expansion, etc. `ColumnDefinitions` in the AdvancedTable kit is
|
11
|
+
`columnDefinitions` maps to the columns prop on the Tanstack table. Column definitions are the single most important part of building a table as they are responsible for building the underlying data model that is used for all sorting, expansion, etc. `ColumnDefinitions` in the AdvancedTable kit is an array of objects as seen in the code snippet below. Each object within the array has two REQUIRED items:
|
12
12
|
|
13
13
|
- `accessor`: this is the key from your data for the value you want rendered in that column
|
14
14
|
- `label`: this is what will be rendered as the column header label
|
@@ -1,3 +1,3 @@
|
|
1
1
|
the optional `loading` prop takes a boolean value that can be managed using state. If loading is true, the table will display the loading skeleton and once loading is false, the table will render with the data provided.
|
2
2
|
|
3
|
-
By default, the inital row count of the loading skeleton is set to 10. If you want more control over this initial row count, the optional `initialLoadingRowCount` prop can be used to
|
3
|
+
By default, the inital row count of the loading skeleton is set to 10. If you want more control over this initial row count, the optional `initialLoadingRowCount` prop can be used to pass in a number. __NOTE__: This is only for the first render of the table, subsequent loading skeleton row count logic is handled within the kit itself.
|
@@ -1,3 +1,3 @@
|
|
1
1
|
`subRowHeaders` is an optional prop that if present will add header rows at each level of the nested data. The prop takes an array of strings, each string being the text for each header row. The array of strings must be in the order in which they need to be rendered in the UI according to depth.
|
2
2
|
|
3
|
-
`enableToggleExpansion` is an additional optional prop that can be used in conjunction with the subRowHeaders prop. `enableToggleExpansion` is a string that can be 'all'
|
3
|
+
`enableToggleExpansion` is an additional optional prop that can be used in conjunction with the subRowHeaders prop. `enableToggleExpansion` is a string that can be 'all', 'header" or "none". If set to 'all', the toggle exapansion button will appear in the table header as well as in the subRow headers. If set to 'header' button will only appear in header and NOT in subRow headers. This is set to 'header' by default.
|
@@ -1,3 +1,3 @@
|
|
1
1
|
The Tanstack table consumes the useReactTable hook to create the table. This hook takes an object that can contain any of the functions that the Tanstack table provides. The advancedTable's optional `tableOptions` can be used to pass tanstack options to the kit.
|
2
2
|
|
3
|
-
In the above example, we are using the initialState option provided by tanstack that takes sort as one of it's values. Setting it to true for the first column is reversing the sort order on first render of the table. For a complete list of possible options and
|
3
|
+
In the above example, we are using the initialState option provided by tanstack that takes sort as one of it's values. Setting it to true for the first column is reversing the sort order on first render of the table. For a complete list of possible options and how to use them, see [here](https://tanstack.com/table/v8/docs/api/core/table#usereacttable--createsolidtable--usevuetable--createsveltetable)
|
@@ -1,11 +1,31 @@
|
|
1
1
|
![date-alignment](https://github.com/powerhome/playbook/assets/92755007/094761cb-5151-4de5-a8e1-f905455c2aca)
|
2
2
|
|
3
3
|
```swift
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
VStack(spacing: Spacing.small) {
|
5
|
+
HStack {
|
6
|
+
PBDate(
|
7
|
+
Date().makeDate(year: 1995, month: 12, day: 25),
|
8
|
+
variant: .standard,
|
9
|
+
typography: .title4
|
10
|
+
)
|
11
|
+
}
|
12
|
+
.frame(maxWidth: .infinity, alignment: .leading)
|
13
|
+
HStack {
|
14
|
+
PBDate(
|
15
|
+
Date().makeDate(year: 2020, month: 12, day: 25),
|
16
|
+
variant: .withIcon(isStandard: true),
|
17
|
+
typography: .title4,
|
18
|
+
iconSize: .x1
|
19
|
+
)
|
20
|
+
}
|
21
|
+
.frame(maxWidth: .infinity, alignment: .center)
|
22
|
+
HStack {
|
23
|
+
PBDate(
|
24
|
+
Date(),
|
25
|
+
variant: .short,
|
26
|
+
typography: .title4
|
27
|
+
)
|
28
|
+
}
|
29
|
+
.frame(maxWidth: .infinity, alignment: .trailing)
|
9
30
|
}
|
10
|
-
|
11
31
|
```
|
@@ -2,15 +2,34 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
```swift
|
5
|
-
|
6
5
|
VStack(alignment: .leading, spacing: Spacing.small) {
|
7
|
-
PBDate(
|
8
|
-
|
9
|
-
|
6
|
+
PBDate(
|
7
|
+
Date(),
|
8
|
+
variant: .short
|
9
|
+
)
|
10
|
+
PBDate(
|
11
|
+
Date().makeDate(year: 2012, month: 8, day: 3),
|
12
|
+
variant: .standard
|
13
|
+
)
|
14
|
+
PBDate(
|
15
|
+
Date().makeDate(year: 2017, month: 12, day: 3),
|
16
|
+
variant: .dayDate(showYear: true)
|
17
|
+
)
|
10
18
|
Spacer()
|
11
|
-
PBDate(
|
12
|
-
|
13
|
-
|
19
|
+
PBDate(
|
20
|
+
Date(),
|
21
|
+
variant: .short,
|
22
|
+
typography: .title4
|
23
|
+
)
|
24
|
+
PBDate(
|
25
|
+
Date().makeDate(year: 2012, month: 8, day: 3),
|
26
|
+
variant: .standard,
|
27
|
+
typography: .title4
|
28
|
+
)
|
29
|
+
PBDate(
|
30
|
+
Date().makeDate(year: 2017, month: 12, day: 3),
|
31
|
+
variant: .dayDate(showYear: true),
|
32
|
+
typography: .title4
|
33
|
+
)
|
14
34
|
}
|
15
|
-
|
16
35
|
```
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from 'react'
|
1
|
+
import React, { ReactSVGElement } from 'react'
|
2
2
|
import classnames from 'classnames'
|
3
3
|
import { buildAriaProps, buildDataProps, buildHtmlProps } from '../utilities/props'
|
4
4
|
import { GlobalProps, globalProps } from '../utilities/globalProps'
|
@@ -27,7 +27,7 @@ type IconProps = {
|
|
27
27
|
data?: {[key: string]: string},
|
28
28
|
fixedWidth?: boolean,
|
29
29
|
flip?: "horizontal" | "vertical" | "both" | "none",
|
30
|
-
icon: string,
|
30
|
+
icon: string | ReactSVGElement,
|
31
31
|
htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
|
32
32
|
id?: string,
|
33
33
|
inverse?: boolean,
|
@@ -47,6 +47,11 @@ const flipMap = {
|
|
47
47
|
none: ""
|
48
48
|
}
|
49
49
|
|
50
|
+
declare global {
|
51
|
+
// eslint-disable-next-line no-var
|
52
|
+
var PB_ICONS: {[key: string]: React.FunctionComponent<any>}
|
53
|
+
}
|
54
|
+
|
50
55
|
const Icon = (props: IconProps) => {
|
51
56
|
const {
|
52
57
|
aria = {},
|
@@ -57,7 +62,7 @@ const Icon = (props: IconProps) => {
|
|
57
62
|
fixedWidth = true,
|
58
63
|
flip = "none",
|
59
64
|
htmlOptions = {},
|
60
|
-
icon,
|
65
|
+
icon = "",
|
61
66
|
id,
|
62
67
|
inverse = false,
|
63
68
|
listItem = false,
|
@@ -69,6 +74,8 @@ const Icon = (props: IconProps) => {
|
|
69
74
|
spin = false,
|
70
75
|
} = props
|
71
76
|
|
77
|
+
let iconElement: ReactSVGElement | null = typeof(icon) === "object" ? icon : null
|
78
|
+
|
72
79
|
const faClasses = {
|
73
80
|
'fa-border': border,
|
74
81
|
'fa-fw': fixedWidth,
|
@@ -79,19 +86,23 @@ const Icon = (props: IconProps) => {
|
|
79
86
|
[`fa-${size}`]: size,
|
80
87
|
[`fa-pull-${pull}`]: pull,
|
81
88
|
[`fa-rotate-${rotation}`]: rotation,
|
89
|
+
}
|
90
|
+
|
91
|
+
if (!customIcon && !iconElement) {
|
92
|
+
const PowerIcon: React.FunctionComponent<any> | undefined =
|
93
|
+
window.PB_ICONS ? window.PB_ICONS[icon as string] : null
|
82
94
|
|
95
|
+
if (PowerIcon) {
|
96
|
+
iconElement = <PowerIcon /> as ReactSVGElement
|
97
|
+
} else {
|
98
|
+
faClasses[`fa-${icon}`] = icon as string
|
99
|
+
}
|
83
100
|
}
|
84
101
|
|
85
|
-
// Lets check and see if the icon prop is referring to a custom Power icon...
|
86
|
-
// If so, then set fa-icon to "custom"
|
87
|
-
// this ensures the JS will not do any further operations
|
88
|
-
// faClasses[`fa-${icon}`] = customIcon ? 'custom' : icon
|
89
|
-
if (!customIcon) faClasses[`fa-${icon}`] = icon
|
90
|
-
|
91
102
|
const classes = classnames(
|
92
103
|
flipMap[flip],
|
93
|
-
'pb_icon_kit',
|
94
|
-
customIcon ? '' : fontStyle,
|
104
|
+
(!iconElement && !customIcon) ? 'pb_icon_kit' : '',
|
105
|
+
(iconElement || customIcon) ? 'pb_custom_icon' : fontStyle,
|
95
106
|
faClasses,
|
96
107
|
globalProps(props),
|
97
108
|
className
|
@@ -110,20 +121,22 @@ const Icon = (props: IconProps) => {
|
|
110
121
|
|
111
122
|
// Add a conditional here to show only the SVG if custom
|
112
123
|
const displaySVG = (customIcon: any) => {
|
113
|
-
if (customIcon)
|
124
|
+
if (iconElement || customIcon)
|
114
125
|
return (
|
115
126
|
<>
|
116
127
|
{
|
117
|
-
React.cloneElement(customIcon, {
|
128
|
+
React.cloneElement(iconElement || customIcon, {
|
118
129
|
...dataProps,
|
119
130
|
...htmlProps,
|
120
131
|
className: classes,
|
121
132
|
id,
|
133
|
+
width: 'auto',
|
134
|
+
height: 'auto',
|
122
135
|
})
|
123
136
|
}
|
124
137
|
</>
|
125
138
|
)
|
126
|
-
else if (isValidEmoji(icon))
|
139
|
+
else if (isValidEmoji(icon as string))
|
127
140
|
return (
|
128
141
|
<>
|
129
142
|
<span
|
@@ -136,7 +149,6 @@ const Icon = (props: IconProps) => {
|
|
136
149
|
</span>
|
137
150
|
</>
|
138
151
|
)
|
139
|
-
|
140
152
|
else
|
141
153
|
return (
|
142
154
|
<>
|
@@ -161,4 +173,4 @@ const Icon = (props: IconProps) => {
|
|
161
173
|
)
|
162
174
|
}
|
163
175
|
|
164
|
-
export default Icon
|
176
|
+
export default Icon
|
@@ -2,15 +2,9 @@
|
|
2
2
|
<div class="icon-wrapper">
|
3
3
|
|
4
4
|
<% svg_url = "https://upload.wikimedia.org/wikipedia/commons/3/3b/Wrench_font_awesome.svg" %>
|
5
|
-
<p><%= pb_rails("icon", props: {
|
6
|
-
<p><%= pb_rails("icon", props: { rotation: 90,
|
7
|
-
<p><%= pb_rails("icon", props: { spin: true,
|
8
|
-
<p><%= pb_rails("icon", props: { size: "5x",
|
9
|
-
<p><%= pb_rails("icon", props: { flip: "horizontal", size: "5x",
|
10
|
-
|
11
|
-
<%= pb_rails("body", props: {
|
12
|
-
text: "Custom icons are compatible with other icon props (size, rotation,
|
13
|
-
spin, flip, etc). Their SVG fill colors will be inherited from
|
14
|
-
parent element's css color properties."
|
15
|
-
} ) %>
|
5
|
+
<p><%= pb_rails("icon", props: { icon: svg_url } ) %></p>
|
6
|
+
<p><%= pb_rails("icon", props: { rotation: 90, icon: svg_url, size: "2x" } ) %></p>
|
7
|
+
<p><%= pb_rails("icon", props: { spin: true, icon: svg_url, size: "3x" } ) %></p>
|
8
|
+
<p><%= pb_rails("icon", props: { size: "5x", icon: svg_url } ) %></p>
|
9
|
+
<p><%= pb_rails("icon", props: { flip: "horizontal", size: "5x", icon: svg_url } ) %></p>
|
16
10
|
</div>
|
@@ -1,33 +1,59 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import { Icon } from '../../'
|
3
3
|
|
4
|
-
// import Icons as config from 'power-icons'
|
5
4
|
const config = {
|
6
|
-
|
7
|
-
<svg
|
8
|
-
ariaHidden="true"
|
9
|
-
focusable="false"
|
10
|
-
role="img"
|
11
|
-
viewBox="0 0 512 512"
|
5
|
+
icon: (
|
6
|
+
<svg viewBox="0 -256 1792 1792"
|
12
7
|
xmlns="http://www.w3.org/2000/svg"
|
13
8
|
>
|
14
|
-
<
|
15
|
-
d="
|
16
|
-
|
17
|
-
/>
|
9
|
+
<g transform="matrix(1,0,0,-1,53.152542,1217.0847)">
|
10
|
+
<path d="m 384,64 q 0,26 -19,45 -19,19 -45,19 -26,0 -45,-19 -19,-19 -19,-45 0,-26 19,-45 19,-19 45,-19 26,0 45,19 19,19 19,45 z m 644,420 -682,-682 q -37,-37 -90,-37 -52,0 -91,37 L 59,-90 Q 21,-54 21,0 21,53 59,91 L 740,772 Q 779,674 854.5,598.5 930,523 1028,484 z m 634,435 q 0,-39 -23,-106 Q 1592,679 1474.5,595.5 1357,512 1216,512 1031,512 899.5,643.5 768,775 768,960 q 0,185 131.5,316.5 131.5,131.5 316.5,131.5 58,0 121.5,-16.5 63.5,-16.5 107.5,-46.5 16,-11 16,-28 0,-17 -16,-28 L 1152,1120 V 896 l 193,-107 q 5,3 79,48.5 74,45.5 135.5,81 61.5,35.5 70.5,35.5 15,0 23.5,-10 8.5,-10 8.5,-25 z" />
|
11
|
+
</g>
|
18
12
|
</svg>
|
19
13
|
),
|
20
14
|
}
|
21
15
|
|
22
16
|
const IconCustom = (props) => {
|
23
17
|
return (
|
24
|
-
<
|
25
|
-
<
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
<React.Fragment>
|
19
|
+
<p>
|
20
|
+
<Icon
|
21
|
+
icon={config.icon}
|
22
|
+
{...props}
|
23
|
+
/>
|
24
|
+
</p>
|
25
|
+
<p>
|
26
|
+
<Icon
|
27
|
+
icon={config.icon}
|
28
|
+
rotation={90}
|
29
|
+
size="2x"
|
30
|
+
{...props}
|
31
|
+
/>
|
32
|
+
</p>
|
33
|
+
<p>
|
34
|
+
<Icon
|
35
|
+
icon={config.icon}
|
36
|
+
size="3x"
|
37
|
+
spin
|
38
|
+
{...props}
|
39
|
+
/>
|
40
|
+
</p>
|
41
|
+
<p>
|
42
|
+
<Icon
|
43
|
+
icon={config.icon}
|
44
|
+
size="5x"
|
45
|
+
{...props}
|
46
|
+
/>
|
47
|
+
</p>
|
48
|
+
<p>
|
49
|
+
<Icon
|
50
|
+
flip="horizontal"
|
51
|
+
icon={config.icon}
|
52
|
+
size="5x"
|
53
|
+
{...props}
|
54
|
+
/>
|
55
|
+
</p>
|
56
|
+
</React.Fragment>
|
31
57
|
)
|
32
58
|
}
|
33
59
|
|
@@ -4,16 +4,12 @@ When using custom icons it is important to introduce a "clean" SVG. In order to
|
|
4
4
|
|
5
5
|
Attributes must be React compatible e.g. <code>xmlns:xlink</code> should be <code>xmlnsXlink</code> and so on. <strong>There should be no hyphenated attributes and no semi-colons!.</strong>
|
6
6
|
|
7
|
-
Fill colors with regards to <code>g</code> or <code>path</code> nodes, e.g. <code>fill="black"</code>, should be replaced with
|
7
|
+
Fill colors with regards to <code>g</code> or <code>path</code> nodes, e.g. <code>fill="black"</code>, should be replaced with <code>currentColor</code> ala <code>fill="currentColor"</code>. Your mileage may vary depending on the complexity of your SVG.
|
8
8
|
|
9
|
-
Pay attention to your custom icon's dimensions and `viewBox` attribute. It is best to use a `viewBox="0 0 512 512"` starting point
|
9
|
+
Pay attention to your custom icon's dimensions and `viewBox` attribute. It is best to use a `viewBox="0 0 512 512"` starting point **when designing instead of trying to retrofit the viewbox afterwards**!
|
10
10
|
|
11
|
-
You must source
|
12
|
-
|
13
|
-
### React
|
14
|
-
|
15
|
-
So long as you have a valid React `<SVG>` node, you can send it as the `customIcon` prop and the kit will take care of the rest.
|
11
|
+
You must source _your own SVG into component/view_ you are working on. This can easily be done in programmatic and maintainable ways.
|
16
12
|
|
17
13
|
### Rails
|
18
14
|
|
19
|
-
|
15
|
+
Sending the absolute path to the `icon` prop results in an `<SVG>` tag within the working view.
|
@@ -1,7 +1,9 @@
|
|
1
|
-
<% if object.
|
2
|
-
<%= object.render_svg
|
3
|
-
<% elsif object.valid_emoji
|
4
|
-
<span class="pb_icon_kit_emoji"
|
1
|
+
<% if object.is_svg? %>
|
2
|
+
<%= object.render_svg %>
|
3
|
+
<% elsif object.valid_emoji? %>
|
4
|
+
<span class="pb_icon_kit_emoji">
|
5
|
+
<%= object.icon.html_safe %>
|
6
|
+
</span>
|
5
7
|
<% else %>
|
6
8
|
<%= content_tag(:i, nil,
|
7
9
|
id: object.id,
|
@@ -38,7 +38,7 @@ module Playbook
|
|
38
38
|
prop :spin, type: Playbook::Props::Boolean,
|
39
39
|
default: false
|
40
40
|
|
41
|
-
def valid_emoji
|
41
|
+
def valid_emoji?
|
42
42
|
emoji_regex = /\p{Emoji}/
|
43
43
|
emoji_regex.match?(icon)
|
44
44
|
end
|
@@ -79,19 +79,36 @@ module Playbook
|
|
79
79
|
)
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
82
|
+
def asset_path
|
83
|
+
return unless Rails.application.config.respond_to?(:icon_path)
|
84
|
+
return unless Dir.entries(Rails.application.config.icon_path).include? "#{icon}.svg"
|
85
|
+
|
86
|
+
Rails.root.join(Rails.application.config.icon_path, "#{icon}.svg")
|
87
|
+
end
|
88
|
+
|
89
|
+
def render_svg
|
90
|
+
doc = Nokogiri::XML(URI.open(asset_path || icon || custom_icon)) # rubocop:disable Security/Open
|
91
|
+
svg = doc.at_css "svg"
|
92
|
+
svg["class"] = "pb_custom_icon " + object.custom_icon_classname
|
93
|
+
svg["id"] = object.id
|
94
|
+
svg["data"] = object.data
|
95
|
+
svg["aria"] = object.aria
|
96
|
+
svg["height"] = "auto"
|
97
|
+
svg["width"] = "auto"
|
98
|
+
doc.at_css("path")["fill"] = "currentColor"
|
99
|
+
raw doc
|
100
|
+
end
|
101
|
+
|
102
|
+
def is_svg?
|
103
|
+
(icon || custom_icon.to_s).include?(".svg") || asset_path.present?
|
91
104
|
end
|
92
105
|
|
93
106
|
private
|
94
107
|
|
108
|
+
def svg_size
|
109
|
+
size.nil? ? "1x" : size
|
110
|
+
end
|
111
|
+
|
95
112
|
def border_class
|
96
113
|
border ? "fa-border" : nil
|
97
114
|
end
|
@@ -1 +1 @@
|
|
1
|
-
This multi kit
|
1
|
+
This multi kit consists of a an avatar, a status, a caption, a body text, and a time stamp, all of which are optional.
|