playbook_ui 14.8.0.pre.alpha.PLAY1598floatinguiupgrade4563 → 14.8.0.pre.alpha.PLAY1615movenegativetoleftofcurrencysign4539

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: 9353b3b402295905df0220cec1a5c043cdfaf017635cfb8e53887a581f1932ca
4
- data.tar.gz: d68b282ac69c6ea7d57e48b7aaee56682c0247fff6ca297c54e1a8c70cf2a7d3
3
+ metadata.gz: fd8c9650b23708306eeea2d36f0a87f8b065d8aa28fbd72bfef581827414c6da
4
+ data.tar.gz: e941e09a241073a2641e0a42b5e3b42e67db2cc6ea4fdf903d54bf8986b3e13c
5
5
  SHA512:
6
- metadata.gz: d32c0d53ed43c2f064913f1a73499f8652bb1c13a388646721590fd9cd8c0f57893c912b9d0d1530e3bf28b779567a260e69a66046847186b1e4a4a9a6e0613f
7
- data.tar.gz: 1432f779bd804e750f0cee0e9b4fe1adcf01ba489c9a1da7f3495684320cb8cdb2f7d2755316c69f4548404fc1106eea396d4c0a1e2835a3cab970816bb0e904
6
+ metadata.gz: 2ffec4416dafad8b69973e7f96276279ecdfc2aa2a9ada8c002a188fe99061db0b22a2a8a5b662a661bab1562b961b3c3db8f8924959b859383c1e9d17e4483b
7
+ data.tar.gz: d2b75f2d74f6ddb913b171976b07a372cbfa539524e06f36ece2f82dd377e66087290830c64735ddf9c158ded7fdb97aaab9fb6c6f1932df364104ef0a661b3e
@@ -101,7 +101,11 @@ const Currency = (props: CurrencyProps): React.ReactElement => {
101
101
  return decimalPart ? `${formattedWhole}.${decimalPart}` : formattedWhole;
102
102
  }
103
103
 
104
- const getAmount = abbreviate ? getAbbreviatedValue('amount') : formatAmount(getMatchingDecimalAmount)
104
+ const swapNegative = size === "sm" && symbol !== ""
105
+ const handleNegative = amount.startsWith("-") && swapNegative ? "-" : ""
106
+ const getAbsoluteAmount = (amountString) => 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: abbreviate ? abbreviated_value : formatted_amount,
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