playbook_ui 10.21.0.pre.alpha.jg1 → 10.21.0
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/pb_avatar/_avatar.scss +2 -2
- data/app/pb_kits/playbook/pb_avatar/{_avatar.jsx → _avatar.tsx} +13 -14
- data/app/pb_kits/playbook/pb_avatar/avatar.rb +1 -1
- data/app/pb_kits/playbook/pb_avatar/avatar.test.js +1 -1
- data/app/pb_kits/playbook/pb_avatar_action_button/_avatar_action_button.jsx +1 -1
- data/app/pb_kits/playbook/pb_background/_background.jsx +1 -1
- data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.jsx +5 -1
- data/app/pb_kits/playbook/pb_bar_graph/bar_graph.rb +1 -0
- data/app/pb_kits/playbook/pb_bread_crumbs/_bread_crumb_item.jsx +1 -1
- data/app/pb_kits/playbook/pb_bread_crumbs/_bread_crumbs.jsx +1 -1
- data/app/pb_kits/playbook/pb_button/_button.jsx +5 -4
- data/app/pb_kits/playbook/pb_button/_button.scss +18 -1
- data/app/pb_kits/playbook/pb_button/button.rb +11 -3
- data/app/pb_kits/playbook/pb_button/button.test.js +13 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_size.html.erb +3 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_size.jsx +26 -0
- data/app/pb_kits/playbook/pb_button/docs/_button_size.md +1 -0
- data/app/pb_kits/playbook/pb_button/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_button/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_button_toolbar/_button_toolbar.jsx +1 -1
- data/app/pb_kits/playbook/pb_caption/_caption.jsx +1 -1
- data/app/pb_kits/playbook/pb_card/_card.jsx +1 -1
- data/app/pb_kits/playbook/pb_checkbox/_checkbox.jsx +1 -1
- data/app/pb_kits/playbook/pb_circle_chart/_circle_chart.jsx +3 -0
- data/app/pb_kits/playbook/pb_circle_chart/circle_chart.rb +1 -0
- data/app/pb_kits/playbook/pb_circle_icon_button/_circle_icon_button.jsx +1 -1
- data/app/pb_kits/playbook/pb_collapsible/_collapsible.jsx +1 -1
- data/app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleContent.jsx +1 -1
- data/app/pb_kits/playbook/pb_currency/_currency.jsx +24 -3
- data/app/pb_kits/playbook/pb_currency/currency.rb +12 -3
- data/app/pb_kits/playbook/pb_currency/currency.test.js +35 -0
- data/app/pb_kits/playbook/pb_currency/docs/_currency_abbreviated.html.erb +27 -0
- data/app/pb_kits/playbook/pb_currency/docs/_currency_abbreviated.jsx +44 -0
- data/app/pb_kits/playbook/pb_currency/docs/_currency_variants.html.erb +1 -1
- data/app/pb_kits/playbook/pb_currency/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_currency/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_dashboard/pbChartsDarkTheme.js +215 -0
- data/app/pb_kits/playbook/pb_dashboard_value/_dashboard_value.jsx +1 -1
- data/app/pb_kits/playbook/pb_dialog/_dialog.jsx +1 -1
- data/app/pb_kits/playbook/pb_dialog/child_kits/_dialog_body.jsx +1 -1
- data/app/pb_kits/playbook/pb_dialog/child_kits/_dialog_footer.jsx +1 -1
- data/app/pb_kits/playbook/pb_dialog/child_kits/_dialog_header.jsx +1 -1
- data/app/pb_kits/playbook/pb_distribution_bar/_distribution_bar.jsx +1 -1
- data/app/pb_kits/playbook/pb_file_upload/_file_upload.jsx +17 -10
- data/app/pb_kits/playbook/pb_file_upload/fileupload.test.js +40 -0
- data/app/pb_kits/playbook/pb_filter/Filter/FilterBackground.jsx +1 -1
- data/app/pb_kits/playbook/pb_flex/_flex.jsx +1 -1
- data/app/pb_kits/playbook/pb_flex/_flex_item.jsx +1 -1
- data/app/pb_kits/playbook/pb_form_group/_form_group.jsx +1 -1
- data/app/pb_kits/playbook/pb_form_pill/_form_pill.jsx +2 -2
- data/app/pb_kits/playbook/pb_gauge/_gauge.jsx +3 -0
- data/app/pb_kits/playbook/pb_gauge/gauge.rb +1 -0
- data/app/pb_kits/playbook/pb_highlight/_highlight.jsx +1 -1
- data/app/pb_kits/playbook/pb_icon/_icon.jsx +1 -1
- data/app/pb_kits/playbook/pb_icon_stat_value/_icon_stat_value.jsx +1 -1
- data/app/pb_kits/playbook/pb_image/_image.scss +3 -3
- data/app/pb_kits/playbook/pb_image/{_image.jsx → _image.tsx} +11 -15
- data/app/pb_kits/playbook/pb_image/image.rb +1 -1
- data/app/pb_kits/playbook/pb_image/image.test.js +1 -1
- data/app/pb_kits/playbook/pb_label_pill/_label_pill.jsx +1 -1
- data/app/pb_kits/playbook/pb_layout/_layout.jsx +1 -1
- data/app/pb_kits/playbook/pb_line_graph/_line_graph.jsx +5 -1
- data/app/pb_kits/playbook/pb_line_graph/line_graph.rb +1 -0
- data/app/pb_kits/playbook/pb_list/_list.jsx +1 -1
- data/app/pb_kits/playbook/pb_list/_list_item.jsx +1 -1
- data/app/pb_kits/playbook/pb_multiple_users/_multiple_users.jsx +1 -1
- data/app/pb_kits/playbook/pb_online_status/{_online_status.jsx → _online_status.tsx} +4 -6
- data/app/pb_kits/playbook/pb_passphrase/_passphrase.jsx +2 -1
- data/app/pb_kits/playbook/pb_pill/_pill.jsx +1 -1
- data/app/pb_kits/playbook/pb_popover/_popover.jsx +3 -5
- data/app/pb_kits/playbook/pb_popover/docs/_popover_close.html.erb +7 -7
- data/app/pb_kits/playbook/pb_popover/index.js +4 -9
- data/app/pb_kits/playbook/pb_popover/popover.html.erb +1 -1
- data/app/pb_kits/playbook/pb_progress_simple/_progress_simple.jsx +1 -1
- data/app/pb_kits/playbook/pb_progress_step/_progress_step.jsx +1 -1
- data/app/pb_kits/playbook/pb_radio/_radio.jsx +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.jsx +5 -0
- data/app/pb_kits/playbook/pb_table/_table.jsx +1 -1
- data/app/pb_kits/playbook/pb_table/_table_row.jsx +1 -1
- data/app/pb_kits/playbook/pb_text_input/_text_input.jsx +1 -1
- data/app/pb_kits/playbook/pb_text_input/_text_input.scss +1 -1
- data/app/pb_kits/playbook/pb_text_input/text_input.test.js +14 -0
- data/app/pb_kits/playbook/pb_textarea/_textarea.jsx +1 -0
- data/app/pb_kits/playbook/pb_time/_time.jsx +1 -1
- data/app/pb_kits/playbook/pb_title/_title.jsx +1 -1
- data/app/pb_kits/playbook/pb_toggle/_toggle.jsx +1 -1
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.jsx +1 -1
- data/app/pb_kits/playbook/pb_user_badge/_user_badge.jsx +1 -1
- data/app/pb_kits/playbook/pb_walkthrough/_walkthrough.jsx +1 -1
- data/app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.jsx +1 -1
- data/app/pb_kits/playbook/plugins/pb_chart.js +8 -4
- data/app/pb_kits/playbook/utilities/globalProps.ts +156 -0
- data/app/pb_kits/playbook/utilities/{props.js → props.ts} +9 -7
- data/lib/playbook/version.rb +1 -1
- metadata +17 -10
- data/app/pb_kits/playbook/types.js +0 -4
- data/app/pb_kits/playbook/utilities/globalProps.js +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a59d79cb7efc701b2cfcda8f853e5d47f6e7a8bb0c63a26ea1fb1a0d1352d7ef
|
4
|
+
data.tar.gz: 4ce8a5b16f4dd0d58a56793bc8aaf8f7e285104fae767a7e4867853ea6531a5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e213335bf164b63b39d2958360e6629c0f16cc07ea01fa2a645f36878fc531c5d4a4e84d8f8aa388c68bb9a92961727399297f45048e9cc7ea5e4d54078b18
|
7
|
+
data.tar.gz: 341993d316fbe3a2cad5b26861ae255128657a13505100aa12b46afd2694aa993fa7210f67faa86b2a2f79b9a8ed999d4786cb7a31512c75080aef5198283d72
|
@@ -16,8 +16,8 @@ $avatar-sizes: (
|
|
16
16
|
position: relative;
|
17
17
|
|
18
18
|
@each $name, $size in $avatar-sizes {
|
19
|
-
&[class*=
|
20
|
-
&[class*=
|
19
|
+
&[class*=_size_#{$name}],
|
20
|
+
&[class*=_size_#{$name}_thumb] {
|
21
21
|
width: $size;
|
22
22
|
height: $size;
|
23
23
|
object-fit: cover;
|
@@ -1,8 +1,5 @@
|
|
1
|
-
/* @flow */
|
2
|
-
|
3
1
|
import React, { useState } from 'react'
|
4
2
|
import classnames from 'classnames'
|
5
|
-
import { map } from 'lodash'
|
6
3
|
|
7
4
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
8
5
|
import { globalProps } from '../utilities/globalProps'
|
@@ -11,9 +8,9 @@ import Image from '../pb_image/_image'
|
|
11
8
|
import OnlineStatus from '../pb_online_status/_online_status'
|
12
9
|
|
13
10
|
type AvatarProps = {
|
14
|
-
aria?:
|
11
|
+
aria?: {[key: string]: string},
|
15
12
|
className?: string,
|
16
|
-
data?:
|
13
|
+
data?: {[key: string]: string},
|
17
14
|
dark?: boolean,
|
18
15
|
id?: string,
|
19
16
|
imageAlt?: string,
|
@@ -23,8 +20,8 @@ type AvatarProps = {
|
|
23
20
|
status: "away" | "offline" | "online",
|
24
21
|
}
|
25
22
|
|
26
|
-
const firstTwoInitials = (name) =>
|
27
|
-
|
23
|
+
const firstTwoInitials = (name: string) =>
|
24
|
+
name.split(/\s/).map((name) => name[0])
|
28
25
|
.join('')
|
29
26
|
.substring(0, 2)
|
30
27
|
|
@@ -41,10 +38,10 @@ const Avatar = (props: AvatarProps) => {
|
|
41
38
|
status = null,
|
42
39
|
dark = false,
|
43
40
|
} = props
|
44
|
-
const dataProps = buildDataProps(data)
|
45
|
-
const ariaProps = buildAriaProps(aria)
|
41
|
+
const dataProps: {[key: string]: any} = buildDataProps(data)
|
42
|
+
const ariaProps: {[key: string]: any} = buildAriaProps(aria)
|
46
43
|
const classes = classnames(
|
47
|
-
buildCss('pb_avatar_kit', size),
|
44
|
+
buildCss('pb_avatar_kit', `size_${size}`),
|
48
45
|
globalProps(props),
|
49
46
|
className
|
50
47
|
)
|
@@ -55,6 +52,8 @@ const Avatar = (props: AvatarProps) => {
|
|
55
52
|
const [error, setError] = useState(false)
|
56
53
|
const handleError = () => setError(true)
|
57
54
|
|
55
|
+
const canShowImage = imageUrl && !error
|
56
|
+
|
58
57
|
return (
|
59
58
|
<div
|
60
59
|
{...ariaProps}
|
@@ -66,21 +65,21 @@ const Avatar = (props: AvatarProps) => {
|
|
66
65
|
className="avatar_wrapper"
|
67
66
|
data-initials={initials}
|
68
67
|
>
|
69
|
-
|
68
|
+
{ canShowImage && (
|
70
69
|
<Image
|
71
70
|
alt={imageAlt}
|
72
71
|
onError={handleError}
|
73
72
|
url={imageUrl}
|
74
73
|
/>
|
75
|
-
|
74
|
+
)}
|
76
75
|
</div>
|
77
|
-
|
76
|
+
{status && (
|
78
77
|
<OnlineStatus
|
79
78
|
className={`size_${size}`}
|
80
79
|
dark={dark}
|
81
80
|
status={status}
|
82
81
|
/>
|
83
|
-
|
82
|
+
)}
|
84
83
|
</div>
|
85
84
|
)
|
86
85
|
}
|
@@ -22,7 +22,7 @@ test('loads the given image url and name', () => {
|
|
22
22
|
const image = screen.getByAltText(imageAlt)
|
23
23
|
const initials = name.split(/\s/)[0].substr(0, 1) + name.split(/\s/)[1].substr(0, 1)
|
24
24
|
|
25
|
-
expect(kit).toHaveClass('
|
25
|
+
expect(kit).toHaveClass('pb_avatar_kit_size_md')
|
26
26
|
expect(kit).toHaveAttribute('data-initials', initials)
|
27
27
|
expect(image).toHaveAttribute('data-src', imageUrl)
|
28
28
|
expect(image).toHaveAttribute('src', imageUrl)
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
buildCss,
|
9
9
|
buildDataProps,
|
10
10
|
} from '../utilities/props'
|
11
|
-
import { globalProps } from '../utilities/globalProps
|
11
|
+
import { globalProps } from '../utilities/globalProps'
|
12
12
|
|
13
13
|
import Avatar from '../pb_avatar/_avatar'
|
14
14
|
import Icon from '../pb_icon/_icon'
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import React from 'react'
|
4
4
|
import classnames from 'classnames'
|
5
5
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
6
|
-
import { globalProps } from '../utilities/globalProps
|
6
|
+
import { globalProps } from '../utilities/globalProps'
|
7
7
|
|
8
8
|
type BackgroundProps = {
|
9
9
|
alt?: string,
|
@@ -3,11 +3,12 @@
|
|
3
3
|
import React from 'react'
|
4
4
|
import classnames from 'classnames'
|
5
5
|
|
6
|
-
import { globalProps } from '../utilities/globalProps
|
6
|
+
import { globalProps } from '../utilities/globalProps'
|
7
7
|
import pbChart from '../plugins/pb_chart'
|
8
8
|
|
9
9
|
type BarGraphProps = {
|
10
10
|
axisTitle: string,
|
11
|
+
dark?: Boolean,
|
11
12
|
xAxisCategories: array,
|
12
13
|
yAxisMin: number,
|
13
14
|
yAxisMax: number,
|
@@ -30,6 +31,7 @@ type BarGraphProps = {
|
|
30
31
|
export default class BarGraph extends React.Component<BarGraphProps> {
|
31
32
|
static defaultProps = {
|
32
33
|
className: 'pb_bar_graph',
|
34
|
+
dark: false,
|
33
35
|
type: 'column',
|
34
36
|
legend: false,
|
35
37
|
toggleLegendClick: true,
|
@@ -38,6 +40,7 @@ export default class BarGraph extends React.Component<BarGraphProps> {
|
|
38
40
|
componentDidMount() {
|
39
41
|
const {
|
40
42
|
axisTitle,
|
43
|
+
dark,
|
41
44
|
xAxisCategories,
|
42
45
|
yAxisMin,
|
43
46
|
yAxisMax,
|
@@ -56,6 +59,7 @@ export default class BarGraph extends React.Component<BarGraphProps> {
|
|
56
59
|
|
57
60
|
new pbChart(`.${className}`, {
|
58
61
|
axisTitle: axisTitle,
|
62
|
+
dark,
|
59
63
|
chartData: chartData,
|
60
64
|
colors: colors,
|
61
65
|
id: id,
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import React from 'react'
|
4
4
|
import classnames from 'classnames'
|
5
5
|
import { buildAriaProps, buildDataProps } from '../utilities/props'
|
6
|
-
import { globalProps } from '../utilities/globalProps
|
6
|
+
import { globalProps } from '../utilities/globalProps'
|
7
7
|
|
8
8
|
import Icon from '../pb_icon/_icon.jsx'
|
9
9
|
|
@@ -22,7 +22,7 @@ type ButtonPropTypes = {
|
|
22
22
|
loading?: boolean,
|
23
23
|
newWindow?: boolean,
|
24
24
|
onClick?: EventHandler,
|
25
|
-
size
|
25
|
+
size?: 'sm' | 'md' | 'lg',
|
26
26
|
text?: string,
|
27
27
|
type: 'inline' | null,
|
28
28
|
htmlType: string | 'button',
|
@@ -36,19 +36,19 @@ const buttonClassName = (props: ButtonPropTypes) => {
|
|
36
36
|
disabled = false,
|
37
37
|
fullWidth = false,
|
38
38
|
loading = false,
|
39
|
-
size = null,
|
40
39
|
type = 'inline',
|
41
40
|
variant = 'primary',
|
41
|
+
size = null,
|
42
42
|
} = props
|
43
43
|
|
44
44
|
let className = 'pb_button_kit'
|
45
45
|
|
46
46
|
className += `${variant !== null ? `_${variant}` : ''}`
|
47
47
|
className += `${type !== null ? `_${type}` : ''}`
|
48
|
-
className += `${size !== null ? `_${size}` : ''}`
|
49
48
|
className += `${fullWidth ? '_block' : ''}`
|
50
49
|
className += disabled ? '_disabled' : '_enabled'
|
51
50
|
className += loading ? '_loading' : ''
|
51
|
+
className += `${size !== null ? ` size_${size}` : ''}`
|
52
52
|
|
53
53
|
return className
|
54
54
|
}
|
@@ -106,6 +106,7 @@ const Button = (props: ButtonPropTypes) => {
|
|
106
106
|
className={css}
|
107
107
|
href={link}
|
108
108
|
id={id}
|
109
|
+
rel="noreferrer"
|
109
110
|
role="link"
|
110
111
|
target={newWindow ? '_blank' : null}
|
111
112
|
>
|
@@ -1,7 +1,24 @@
|
|
1
1
|
@import "./button_mixins";
|
2
2
|
|
3
|
-
|
3
|
+
$pb_button_sizes: (
|
4
|
+
"sm": 0.75rem,
|
5
|
+
"md": 0.875rem,
|
6
|
+
"lg": 1.125rem,
|
7
|
+
);
|
8
|
+
|
9
|
+
[class*=pb_button_kit]{
|
4
10
|
@include pb_button;
|
11
|
+
// Size =================
|
12
|
+
@each $name, $size in $pb_button_sizes {
|
13
|
+
&[class*=size_#{$name}] {
|
14
|
+
font-size: $size;
|
15
|
+
padding: calc(#{$size} / 2) calc(#{$size} * 2.42) !important;
|
16
|
+
}
|
17
|
+
@if $name == "sm" {
|
18
|
+
min-height: 0;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
5
22
|
// Variants =================
|
6
23
|
&[class*=_primary] {
|
7
24
|
@include pb_button_primary;
|
@@ -18,6 +18,9 @@ module Playbook
|
|
18
18
|
prop :text
|
19
19
|
prop :type
|
20
20
|
prop :value
|
21
|
+
prop :size, type: Playbook::Props::Enum,
|
22
|
+
values: ["sm", "md", "lg", nil],
|
23
|
+
default: nil
|
21
24
|
|
22
25
|
def options
|
23
26
|
{
|
@@ -44,12 +47,13 @@ module Playbook
|
|
44
47
|
link ? "a" : "button"
|
45
48
|
end
|
46
49
|
|
47
|
-
private
|
48
|
-
|
49
50
|
def classname
|
50
|
-
generate_classname("pb_button_kit", variant, full_width_class, disabled_class, loading_class)
|
51
|
+
button_class = generate_classname("pb_button_kit", variant, full_width_class, disabled_class, loading_class)
|
52
|
+
button_class + size_class
|
51
53
|
end
|
52
54
|
|
55
|
+
private
|
56
|
+
|
53
57
|
def disabled_class
|
54
58
|
disabled ? "disabled" : "enabled"
|
55
59
|
end
|
@@ -61,6 +65,10 @@ module Playbook
|
|
61
65
|
def loading_class
|
62
66
|
loading ? "loading" : nil
|
63
67
|
end
|
68
|
+
|
69
|
+
def size_class
|
70
|
+
size ? " size_#{size}" : ""
|
71
|
+
end
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
@@ -89,3 +89,16 @@ test('click event', async () => {
|
|
89
89
|
|
90
90
|
expect(screen.getByText('clicked button!')).toBeInTheDocument()
|
91
91
|
})
|
92
|
+
|
93
|
+
test('size prop', () => {
|
94
|
+
render(
|
95
|
+
<Button
|
96
|
+
data={{ testid: 'size-test' }}
|
97
|
+
size="sm"
|
98
|
+
/>
|
99
|
+
)
|
100
|
+
|
101
|
+
const kit = screen.getByTestId('size-test')
|
102
|
+
|
103
|
+
expect(kit).toHaveClass('pb_button_kit_primary_inline_enabled size_sm')
|
104
|
+
})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { Button } from '../../'
|
3
|
+
|
4
|
+
const ButtonSize = (props) => (
|
5
|
+
<div>
|
6
|
+
<Button
|
7
|
+
size="sm"
|
8
|
+
text="Button sm size"
|
9
|
+
{...props}
|
10
|
+
/>
|
11
|
+
{' '}
|
12
|
+
<Button
|
13
|
+
size="md"
|
14
|
+
text="Button md size"
|
15
|
+
{...props}
|
16
|
+
/>
|
17
|
+
{' '}
|
18
|
+
<Button
|
19
|
+
size="lg"
|
20
|
+
text="Button lg size"
|
21
|
+
{...props}
|
22
|
+
/>
|
23
|
+
</div>
|
24
|
+
)
|
25
|
+
|
26
|
+
export default ButtonSize
|
@@ -0,0 +1 @@
|
|
1
|
+
By default button has the `md` size style, even if you don't explicitly pass a size prop.
|
@@ -7,6 +7,7 @@ examples:
|
|
7
7
|
- button_block_content: Button Block Content
|
8
8
|
- button_accessibility: Button Accessibility Options
|
9
9
|
- button_options: Button Additional Options
|
10
|
+
- button_size: Button Size
|
10
11
|
react:
|
11
12
|
- button_default: Button Variants
|
12
13
|
- button_full_width: Button Full Width
|
@@ -15,3 +16,4 @@ examples:
|
|
15
16
|
- button_block_content: Button Block Content
|
16
17
|
- button_accessibility: Button Accessibility Options
|
17
18
|
- button_options: Button Additional Options (onClick)
|
19
|
+
- button_size: Button Size
|
@@ -5,3 +5,4 @@ export { default as ButtonLoading } from './_button_loading.jsx'
|
|
5
5
|
export { default as ButtonBlockContent } from './_button_block_content.jsx'
|
6
6
|
export { default as ButtonAccessibility } from './_button_accessibility.jsx'
|
7
7
|
export { default as ButtonOptions } from './_button_options.jsx'
|
8
|
+
export { default as ButtonSize } from './_button_size.jsx'
|
@@ -5,7 +5,7 @@ import classnames from 'classnames'
|
|
5
5
|
|
6
6
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
7
7
|
|
8
|
-
import { globalProps } from '../utilities/globalProps
|
8
|
+
import { globalProps } from '../utilities/globalProps'
|
9
9
|
|
10
10
|
type ButtonToolbarProps = {
|
11
11
|
aria?: object,
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import React from 'react'
|
4
4
|
import classnames from 'classnames'
|
5
5
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
6
|
-
import { deprecatedProps, globalProps } from '../utilities/globalProps
|
6
|
+
import { deprecatedProps, globalProps } from '../utilities/globalProps'
|
7
7
|
|
8
8
|
type CaptionProps = {
|
9
9
|
aria?: object,
|
@@ -4,7 +4,7 @@ import React from 'react'
|
|
4
4
|
import { get } from 'lodash'
|
5
5
|
import classnames from 'classnames'
|
6
6
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
7
|
-
import { globalProps } from '../utilities/globalProps
|
7
|
+
import { globalProps } from '../utilities/globalProps'
|
8
8
|
|
9
9
|
type CardPropTypes = {
|
10
10
|
aria?: object,
|
@@ -5,7 +5,7 @@ import Body from '../pb_body/_body.jsx'
|
|
5
5
|
import Icon from '../pb_icon/_icon.jsx'
|
6
6
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
7
7
|
import classnames from 'classnames'
|
8
|
-
import { globalProps } from '../utilities/globalProps
|
8
|
+
import { globalProps } from '../utilities/globalProps'
|
9
9
|
|
10
10
|
type CheckboxProps = {
|
11
11
|
aria?: object,
|
@@ -14,6 +14,7 @@ type CircleChartProps = {
|
|
14
14
|
children: Node,
|
15
15
|
className?: string,
|
16
16
|
colors: array,
|
17
|
+
dark?: Boolean,
|
17
18
|
data?: Object,
|
18
19
|
dataLabelHtml: string,
|
19
20
|
dataLabels: boolean,
|
@@ -40,6 +41,7 @@ const CircleChart = (props: CircleChartProps) => {
|
|
40
41
|
children,
|
41
42
|
className,
|
42
43
|
colors = [],
|
44
|
+
dark = false,
|
43
45
|
data = {},
|
44
46
|
dataLabelHtml = '<div>{point.name}</div>',
|
45
47
|
dataLabels = false,
|
@@ -81,6 +83,7 @@ const CircleChart = (props: CircleChartProps) => {
|
|
81
83
|
borderColor: roundedBorderColor,
|
82
84
|
borderWidth: roundedBorderWidth,
|
83
85
|
chartData: formattedChartData,
|
86
|
+
dark,
|
84
87
|
title,
|
85
88
|
type: style,
|
86
89
|
showInLegend: legend,
|
@@ -7,7 +7,7 @@ import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
|
7
7
|
import type { Callback } from '../types'
|
8
8
|
|
9
9
|
import { noop } from '../utilities/props'
|
10
|
-
import { globalProps } from '../utilities/globalProps
|
10
|
+
import { globalProps } from '../utilities/globalProps'
|
11
11
|
|
12
12
|
import Button from '../pb_button/_button'
|
13
13
|
import Icon from '../pb_icon/_icon'
|
@@ -4,7 +4,7 @@ import React, { useState } from 'react'
|
|
4
4
|
|
5
5
|
import classnames from 'classnames'
|
6
6
|
|
7
|
-
import { globalProps } from '../utilities/globalProps
|
7
|
+
import { globalProps } from '../utilities/globalProps'
|
8
8
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
9
9
|
|
10
10
|
import CollapsibleContent from './child_kits/CollapsibleContent'
|
@@ -4,7 +4,7 @@ import classnames from 'classnames'
|
|
4
4
|
import React, { useContext } from 'react'
|
5
5
|
import AnimateHeight from 'react-animate-height'
|
6
6
|
import { buildCss } from '../../utilities/props'
|
7
|
-
import { globalProps } from '../../utilities/globalProps
|
7
|
+
import { globalProps } from '../../utilities/globalProps'
|
8
8
|
|
9
9
|
import CollapsibleContext from '../context'
|
10
10
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import React from 'react'
|
4
4
|
import classnames from 'classnames'
|
5
5
|
|
6
|
-
import { globalProps } from '../utilities/globalProps
|
6
|
+
import { globalProps } from '../utilities/globalProps'
|
7
7
|
import { buildAriaProps, buildCss, buildDataProps } from '../utilities/props'
|
8
8
|
|
9
9
|
import Body from '../pb_body/_body'
|
@@ -11,6 +11,7 @@ import Caption from '../pb_caption/_caption'
|
|
11
11
|
import Title from '../pb_title/_title'
|
12
12
|
|
13
13
|
type CurrencyProps = {
|
14
|
+
abbreviate?: boolean,
|
14
15
|
align?: 'center' | 'left' | 'right',
|
15
16
|
amount: string,
|
16
17
|
aria?: object,
|
@@ -34,6 +35,7 @@ const sizes = {
|
|
34
35
|
|
35
36
|
const Currency = (props: CurrencyProps) => {
|
36
37
|
const {
|
38
|
+
abbreviate = false,
|
37
39
|
align = 'left',
|
38
40
|
aria = {},
|
39
41
|
amount,
|
@@ -69,6 +71,24 @@ const Currency = (props: CurrencyProps) => {
|
|
69
71
|
className
|
70
72
|
)
|
71
73
|
|
74
|
+
const getFormattedNumber = (input) => new Intl.NumberFormat('en-US', {
|
75
|
+
notation: 'compact',
|
76
|
+
maximumFractionDigits: 1,
|
77
|
+
}).format(input)
|
78
|
+
|
79
|
+
type AbbrType = 'amount' | 'unit'
|
80
|
+
|
81
|
+
const getAbbreviatedValue = (abbrType: AbbrType) => {
|
82
|
+
const num = `${getFormattedNumber(whole.split(',').join(''))}`,
|
83
|
+
isAmount = abbrType === 'amount',
|
84
|
+
isUnit = abbrType === 'unit'
|
85
|
+
return isAmount ? num.slice(0, -1) : isUnit ? num.slice(-1) : ''
|
86
|
+
}
|
87
|
+
|
88
|
+
const getAmount = abbreviate ? getAbbreviatedValue('amount') : whole,
|
89
|
+
getAbbreviation = abbreviate ? getAbbreviatedValue('unit') : null,
|
90
|
+
getDecimalValue = abbreviate ? '' : `.${decimal}`
|
91
|
+
|
72
92
|
return (
|
73
93
|
<div
|
74
94
|
{...ariaProps}
|
@@ -92,7 +112,7 @@ const Currency = (props: CurrencyProps) => {
|
|
92
112
|
dark={dark}
|
93
113
|
size={sizes[size]}
|
94
114
|
>
|
95
|
-
{
|
115
|
+
{getAmount}
|
96
116
|
</Title>
|
97
117
|
|
98
118
|
<Body
|
@@ -100,10 +120,11 @@ const Currency = (props: CurrencyProps) => {
|
|
100
120
|
color="light"
|
101
121
|
dark={dark}
|
102
122
|
>
|
123
|
+
{getAbbreviation}
|
103
124
|
<If condition={unit}>
|
104
125
|
{unit}
|
105
126
|
<Else />
|
106
|
-
{
|
127
|
+
{getDecimalValue}
|
107
128
|
</If>
|
108
129
|
</Body>
|
109
130
|
</div>
|
@@ -33,6 +33,9 @@ module Playbook
|
|
33
33
|
prop :dark, type: Playbook::Props::Boolean,
|
34
34
|
default: false
|
35
35
|
|
36
|
+
prop :abbreviate, type: Playbook::Props::Boolean,
|
37
|
+
default: false
|
38
|
+
|
36
39
|
def classname
|
37
40
|
generate_classname("pb_currency_kit", align, size, dark_class)
|
38
41
|
end
|
@@ -48,7 +51,7 @@ module Playbook
|
|
48
51
|
def title_props
|
49
52
|
{
|
50
53
|
size: size_value,
|
51
|
-
text: whole_value,
|
54
|
+
text: abbreviate ? abbreviated_value : whole_value,
|
52
55
|
classname: "pb_currency_value",
|
53
56
|
dark: dark,
|
54
57
|
}
|
@@ -84,12 +87,18 @@ module Playbook
|
|
84
87
|
amount.split(".").first.to_s
|
85
88
|
end
|
86
89
|
|
90
|
+
def abbreviated_value(index = 0..-2)
|
91
|
+
value = amount.split(".").first.split(",").join("")
|
92
|
+
abbreviated_num = number_to_human(value, units: { thousand: "K", million: "M", billion: "B", trillion: "T" }).gsub(/\s+/, "").to_s
|
93
|
+
abbreviated_num[index]
|
94
|
+
end
|
95
|
+
|
87
96
|
def units_element
|
88
97
|
_, decimal_part = amount.split(".")
|
89
|
-
if unit.nil?
|
98
|
+
if unit.nil? && abbreviate == false
|
90
99
|
decimal_part.nil? ? ".00" : ".#{decimal_part}"
|
91
100
|
else
|
92
|
-
unit
|
101
|
+
abbreviate ? "#{abbreviated_value(-1)}#{unit}" : unit
|
93
102
|
end
|
94
103
|
end
|
95
104
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { render, screen } from '../utilities/test-utils'
|
3
|
+
import Currency from './_currency'
|
4
|
+
|
5
|
+
test('abbreviate prop returns proper abbreviated amount', () => {
|
6
|
+
render(
|
7
|
+
<>
|
8
|
+
<Currency
|
9
|
+
abbreviate
|
10
|
+
amount="3200"
|
11
|
+
data={{ testid: 'test-thousands' }}
|
12
|
+
/>
|
13
|
+
<Currency
|
14
|
+
abbreviate
|
15
|
+
amount="3,200,000"
|
16
|
+
data={{ testid: 'test-millions' }}
|
17
|
+
/>
|
18
|
+
<Currency
|
19
|
+
abbreviate
|
20
|
+
amount="3200000000"
|
21
|
+
data={{ testid: 'test-billions' }}
|
22
|
+
/>
|
23
|
+
<Currency
|
24
|
+
abbreviate
|
25
|
+
amount="3,200,000,000,000"
|
26
|
+
data={{ testid: 'test-trillions' }}
|
27
|
+
/>
|
28
|
+
</>
|
29
|
+
)
|
30
|
+
|
31
|
+
expect(screen.getByTestId('test-thousands')).toHaveTextContent('$3.2K')
|
32
|
+
expect(screen.getByTestId('test-millions')).toHaveTextContent('$3.2M')
|
33
|
+
expect(screen.getByTestId('test-billions')).toHaveTextContent('$3.2B')
|
34
|
+
expect(screen.getByTestId('test-trillions')).toHaveTextContent('$3.2T')
|
35
|
+
})
|