playbook_ui 14.9.0.pre.rc.13 → 14.9.0.pre.rc.14
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_currency/_currency.tsx +7 -3
- data/app/pb_kits/playbook/pb_currency/currency.html.erb +2 -2
- data/app/pb_kits/playbook/pb_currency/currency.rb +17 -1
- data/app/pb_kits/playbook/pb_currency/currency.test.js +40 -3
- data/app/pb_kits/playbook/pb_currency/docs/_currency_negative.html.erb +4 -0
- data/app/pb_kits/playbook/pb_currency/docs/_currency_negative.jsx +16 -0
- 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/dist/chunks/_weekday_stacked-Da_uRFs_.js +45 -0
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +4 -2
- data/dist/chunks/_weekday_stacked-DZMBXSFp.js +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bab858e0ef86e0536cb3f24891e4be7ca0dbcb4a07edd29232784114fdd8fb38
|
4
|
+
data.tar.gz: 5ab99e6d31b1124ecca558cc0908e3179c3cb83ddb4015acfed8f0815af462bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 002d3f1e386098d7c1d8100cd751b4a63733bc4f17da06aefefce51b60ebbbf24f092ed9fe94ba91d80ef6521a24896c7ed70b82f8b9cbe9e44ddd935ecb3b4e
|
7
|
+
data.tar.gz: 75cf8ddd05525230a2f814419375d7929e0960f2a9d1568918751b3f5ecf348be1db3c542f438f818cf943c0c39ae9bde2ce7f14075df6b7268570c7722b809b
|
@@ -101,7 +101,11 @@ const Currency = (props: CurrencyProps): React.ReactElement => {
|
|
101
101
|
return decimalPart ? `${formattedWhole}.${decimalPart}` : formattedWhole;
|
102
102
|
}
|
103
103
|
|
104
|
-
const
|
104
|
+
const swapNegative = size === "sm" && symbol !== ""
|
105
|
+
const handleNegative = amount.startsWith("-") && swapNegative ? "-" : ""
|
106
|
+
const getAbsoluteAmount = (amountString: string) => amountString.replace(/^-/,'')
|
107
|
+
const getAbbrOrFormatAmount = abbreviate ? getAbbreviatedValue('amount') : formatAmount(getMatchingDecimalAmount)
|
108
|
+
const getAmount = swapNegative ? getAbsoluteAmount(getAbbrOrFormatAmount) : getAbbrOrFormatAmount
|
105
109
|
const getAbbreviation = abbreviate ? getAbbreviatedValue('unit') : null
|
106
110
|
const getDecimalValue = abbreviate ? '' : getMatchingDecimalValue
|
107
111
|
|
@@ -118,7 +122,7 @@ const Currency = (props: CurrencyProps): React.ReactElement => {
|
|
118
122
|
<div className={`pb_currency_wrapper${variantClass || emphasizedClass}`}>
|
119
123
|
{unstyled ? (
|
120
124
|
<>
|
121
|
-
<div>{symbol}</div>
|
125
|
+
<div>{handleNegative}{symbol}</div>
|
122
126
|
<div>{getAmount}</div>
|
123
127
|
<div>
|
124
128
|
{getAbbreviation}
|
@@ -132,7 +136,7 @@ const Currency = (props: CurrencyProps): React.ReactElement => {
|
|
132
136
|
color="light"
|
133
137
|
dark={dark}
|
134
138
|
>
|
135
|
-
{symbol}
|
139
|
+
{handleNegative}{symbol}
|
136
140
|
</Body>
|
137
141
|
|
138
142
|
<Title
|
@@ -3,12 +3,12 @@
|
|
3
3
|
|
4
4
|
<div class=<%= "pb_currency_wrapper#{object.variant_class || object.emphasized_class}" %>>
|
5
5
|
<% if object.unstyled %>
|
6
|
-
<div><%= object.symbol %></div>
|
6
|
+
<div><%= object.negative_sign %><%= object.symbol %></div>
|
7
7
|
<div><%= object.title_props[:text] %></div>
|
8
8
|
<div><%= object.body_props[:text] %></div>
|
9
9
|
<% else %>
|
10
10
|
<%= pb_rails("body", props: object.currency_wrapper_props) do %>
|
11
|
-
<%= object.symbol %>
|
11
|
+
<%= object.negative_sign %><%= object.symbol %>
|
12
12
|
<% end %>
|
13
13
|
<%= pb_rails("title", props: object.title_props) %>
|
14
14
|
<%= pb_rails("body", props: object.body_props) %>
|
@@ -68,12 +68,20 @@ module Playbook
|
|
68
68
|
def title_props
|
69
69
|
{
|
70
70
|
size: size_value,
|
71
|
-
text:
|
71
|
+
text: swap_negative ? absolute_amount(abbr_or_format_amount) : abbr_or_format_amount,
|
72
72
|
classname: "pb_currency_value",
|
73
73
|
dark: dark,
|
74
74
|
}
|
75
75
|
end
|
76
76
|
|
77
|
+
def abbr_or_format_amount
|
78
|
+
abbreviate ? abbreviated_value : formatted_amount
|
79
|
+
end
|
80
|
+
|
81
|
+
def negative_sign
|
82
|
+
amount.starts_with?("-") && swap_negative ? "-" : ""
|
83
|
+
end
|
84
|
+
|
77
85
|
def body_props
|
78
86
|
{
|
79
87
|
text: units_element,
|
@@ -159,6 +167,14 @@ module Playbook
|
|
159
167
|
whole_value
|
160
168
|
end
|
161
169
|
end
|
170
|
+
|
171
|
+
def absolute_amount(amount_string)
|
172
|
+
amount_string.sub(/^-/, "")
|
173
|
+
end
|
174
|
+
|
175
|
+
def swap_negative
|
176
|
+
size == "sm" && symbol != ""
|
177
|
+
end
|
162
178
|
end
|
163
179
|
end
|
164
180
|
end
|
@@ -65,7 +65,7 @@ test('decimals default prop returns decimals as body text', () => {
|
|
65
65
|
|
66
66
|
test('commaSeparator prop returns comma separated amount', () => {
|
67
67
|
render(
|
68
|
-
<Currency
|
68
|
+
<Currency
|
69
69
|
amount="1234567890"
|
70
70
|
commaSeparator
|
71
71
|
data={{ testid: 'comma-test' }}
|
@@ -76,7 +76,7 @@ test('commaSeparator prop returns comma separated amount', () => {
|
|
76
76
|
|
77
77
|
test('commaSeparator prop returns comma separated amount with decimals', () => {
|
78
78
|
render(
|
79
|
-
<Currency
|
79
|
+
<Currency
|
80
80
|
amount="1234567890.12"
|
81
81
|
commaSeparator
|
82
82
|
data={{ testid: 'comma-test-decimals' }}
|
@@ -87,7 +87,7 @@ test('commaSeparator prop returns comma separated amount with decimals', () => {
|
|
87
87
|
|
88
88
|
test('commaSeparator prop returns comma separated amount with decimals="matching"', () => {
|
89
89
|
render(
|
90
|
-
<Currency
|
90
|
+
<Currency
|
91
91
|
amount="1234567890.12"
|
92
92
|
commaSeparator
|
93
93
|
data={{ testid: 'comma-test-decimals-matching' }}
|
@@ -96,3 +96,40 @@ test('commaSeparator prop returns comma separated amount with decimals="matching
|
|
96
96
|
)
|
97
97
|
expect(screen.getByTestId('comma-test-decimals-matching')).toHaveTextContent('1,234,567,890.12')
|
98
98
|
})
|
99
|
+
|
100
|
+
test('handles negative amounts correctly', () => {
|
101
|
+
render(
|
102
|
+
<>
|
103
|
+
<Currency
|
104
|
+
amount="-320"
|
105
|
+
data={{ testid: 'test-negative-default' }}
|
106
|
+
/>
|
107
|
+
<Currency
|
108
|
+
abbreviate
|
109
|
+
amount="-3200000"
|
110
|
+
data={{ testid: 'test-negative-millions' }}
|
111
|
+
/>
|
112
|
+
<Currency
|
113
|
+
amount="-123456.78"
|
114
|
+
commaSeparator
|
115
|
+
data={{ testid: 'test-negative-comma-decimals' }}
|
116
|
+
/>
|
117
|
+
<Currency
|
118
|
+
amount="-400.50"
|
119
|
+
data={{ testid: 'test-negative-no-symbol' }}
|
120
|
+
symbol=""
|
121
|
+
/>
|
122
|
+
<Currency
|
123
|
+
amount="-500.55"
|
124
|
+
data={{ testid: 'test-negative-medium-size' }}
|
125
|
+
size="md"
|
126
|
+
/>
|
127
|
+
</>
|
128
|
+
)
|
129
|
+
|
130
|
+
expect(screen.getByTestId('test-negative-default')).toHaveTextContent('-$320')
|
131
|
+
expect(screen.getByTestId('test-negative-millions')).toHaveTextContent('-$3.2M')
|
132
|
+
expect(screen.getByTestId('test-negative-comma-decimals')).toHaveTextContent('-$123,456.78')
|
133
|
+
expect(screen.getByTestId('test-negative-no-symbol')).toHaveTextContent('-400.50')
|
134
|
+
expect(screen.getByTestId('test-negative-medium-size')).toHaveTextContent('$-500.55')
|
135
|
+
})
|
@@ -9,6 +9,7 @@ examples:
|
|
9
9
|
- currency_matching_decimals: Matching Decimals
|
10
10
|
- currency_unstyled: Unstyled
|
11
11
|
- currency_comma_separator: Comma Separator
|
12
|
+
- currency_negative: Negative
|
12
13
|
|
13
14
|
react:
|
14
15
|
- currency_variants: Variants
|
@@ -19,6 +20,7 @@ examples:
|
|
19
20
|
- currency_matching_decimals: Matching Decimals
|
20
21
|
- currency_unstyled: Unstyled
|
21
22
|
- currency_comma_separator: Comma Separator
|
23
|
+
- currency_negative: Negative
|
22
24
|
|
23
25
|
swift:
|
24
26
|
- currency_size_swift: Size
|
@@ -6,3 +6,4 @@ export { default as CurrencyAbbreviated } from './_currency_abbreviated.jsx'
|
|
6
6
|
export { default as CurrencyMatchingDecimals } from './_currency_matching_decimals.jsx'
|
7
7
|
export { default as CurrencyUnstyled } from './_currency_unstyled.jsx'
|
8
8
|
export { default as CurrencyCommaSeparator } from './_currency_comma_separator.jsx'
|
9
|
+
export { default as CurrencyNegative } from './_currency_negative.jsx'
|