playbook_ui 14.9.0.pre.rc.12 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f008d22756b57b8507454a1a51e27dfc9d145bb95f2e85ab6bd38a4e737b5103
4
- data.tar.gz: 990c407a7f972e7189e42b7fea5d4854b72d83b4746cd1030a7301de9a3ede8c
3
+ metadata.gz: bab858e0ef86e0536cb3f24891e4be7ca0dbcb4a07edd29232784114fdd8fb38
4
+ data.tar.gz: 5ab99e6d31b1124ecca558cc0908e3179c3cb83ddb4015acfed8f0815af462bd
5
5
  SHA512:
6
- metadata.gz: f4d2d0829ce2a314b4d220d53d42213d3af2c566ae4d739c9c6e675f6b3289bbbbd8471e02c1749d41496b9eb559af61cd38381c9660c1a074f712f48692b160
7
- data.tar.gz: b55ff1b6906b80b3cbd61ada470258b47db1db2e5caf67e648b53c47d6c430256ea6e6a28c4f925b65458418c70420ada82fa68de483d23ca978bb4f01679e07
6
+ metadata.gz: 002d3f1e386098d7c1d8100cd751b4a63733bc4f17da06aefefce51b60ebbbf24f092ed9fe94ba91d80ef6521a24896c7ed70b82f8b9cbe9e44ddd935ecb3b4e
7
+ data.tar.gz: 75cf8ddd05525230a2f814419375d7929e0960f2a9d1568918751b3f5ecf348be1db3c542f438f818cf943c0c39ae9bde2ce7f14075df6b7268570c7722b809b
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react'
2
2
  import classnames from 'classnames'
3
3
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
4
- import { GlobalProps, globalProps } from '../utilities/globalProps'
4
+ import { GlobalProps, globalProps, globalInlineProps } from '../utilities/globalProps'
5
5
 
6
6
  type BackgroundColors = 'gradient' |
7
7
  'dark' |'light' | 'white' | 'success' | 'warning' | 'error' | 'info' | 'neutral' | 'primary' | 'shadow' |
@@ -145,6 +145,12 @@ const Background = (props: BackgroundProps): React.ReactElement => {
145
145
  } : {})
146
146
  };
147
147
 
148
+ const dynamicInlineProps = globalInlineProps(props);
149
+ const combinedStyles = {
150
+ ...backgroundStyle,
151
+ ...dynamicInlineProps
152
+ };
153
+
148
154
  const Tag: React.ReactElement | any = `${tag}`;
149
155
  const ariaProps = buildAriaProps(aria);
150
156
  const dataProps = buildDataProps(data);
@@ -158,7 +164,7 @@ const Background = (props: BackgroundProps): React.ReactElement => {
158
164
  alt={alt}
159
165
  className={classes}
160
166
  id={id}
161
- style={backgroundStyle}
167
+ style={combinedStyles}
162
168
  >
163
169
  {children}
164
170
  </Tag>
@@ -2,7 +2,7 @@ import React, { useEffect, ReactElement } from 'react'
2
2
  import classnames from 'classnames'
3
3
  import useCollapsible from './useCollapsible'
4
4
 
5
- import { globalProps } from '../utilities/globalProps'
5
+ import { globalProps, globalInlineProps } from '../utilities/globalProps'
6
6
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
7
7
 
8
8
  import CollapsibleContent from './child_kits/CollapsibleContent'
@@ -75,6 +75,7 @@ const Collapsible = ({
75
75
  globalProps(props),
76
76
  className
77
77
  )
78
+ const dynamicInlineProps = globalInlineProps(props)
78
79
  return (
79
80
  <CollapsibleContext.Provider value={{ collapsed: isCollapsed, toggle, icon, iconSize, iconColor, onIconClick, onClick }}>
80
81
  <div
@@ -83,6 +84,7 @@ const Collapsible = ({
83
84
  {...htmlProps}
84
85
  className={classes}
85
86
  id={id}
87
+ style={dynamicInlineProps}
86
88
  >
87
89
  {Main ? (
88
90
  <CollapsibleMain {...mainProps}>
@@ -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: 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: 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
@@ -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
+ })
@@ -0,0 +1,4 @@
1
+ <%= pb_rails("currency", props: {
2
+ amount: "-2,000.50",
3
+ size: "sm",
4
+ }) %>
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+
3
+ import Currency from '../_currency'
4
+
5
+ const CurrencyNegative = (props) => {
6
+ return (
7
+ <>
8
+ <Currency
9
+ amount="-2,000.50"
10
+ {...props}
11
+ />
12
+ </>
13
+ )
14
+ }
15
+
16
+ export default CurrencyNegative
@@ -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'
@@ -7,7 +7,7 @@ import {
7
7
  buildDataProps,
8
8
  buildHtmlProps,
9
9
  } from "../utilities/props";
10
- import { globalProps } from "../utilities/globalProps";
10
+ import { globalProps, globalInlineProps } from "../utilities/globalProps";
11
11
 
12
12
  import { DialogContext } from "../pb_dialog/_dialog_context";
13
13
 
@@ -101,6 +101,8 @@ const Drawer = (props: DrawerProps): React.ReactElement => {
101
101
 
102
102
  const classes = classnames(buildCss("pb_drawer_wrapper"), className);
103
103
 
104
+ const dynamicInlineProps = globalInlineProps(props)
105
+
104
106
  const [triggerOpened, setTriggerOpened] = useState(false);
105
107
 
106
108
  const breakpointWidths: Record<DrawerProps["breakpoint"], number> = {
@@ -198,6 +200,7 @@ const Drawer = (props: DrawerProps): React.ReactElement => {
198
200
  {...dataProps}
199
201
  {...htmlProps}
200
202
  className={classes}
203
+ style={dynamicInlineProps}
201
204
  >
202
205
  {isModalVisible && (
203
206
  <div
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import classnames from 'classnames'
3
- import { GlobalProps, globalProps } from '../utilities/globalProps'
3
+ import { GlobalProps, globalProps, globalInlineProps } from '../utilities/globalProps'
4
4
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
5
5
 
6
6
  type ImageType = {
@@ -41,6 +41,7 @@ const Image = (props: ImageType): React.ReactElement => {
41
41
  globalProps(props),
42
42
  className
43
43
  )
44
+ const dynamicInlineProps = globalInlineProps(props)
44
45
  const dataProps = buildDataProps(data)
45
46
  const htmlProps = buildHtmlProps(htmlOptions)
46
47
 
@@ -56,6 +57,7 @@ const Image = (props: ImageType): React.ReactElement => {
56
57
  id={id}
57
58
  onError={onError}
58
59
  src={url}
60
+ style={dynamicInlineProps}
59
61
  />
60
62
  )
61
63
  }
@@ -2,7 +2,7 @@ import React from 'react'
2
2
  import classnames from 'classnames'
3
3
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
4
4
 
5
- import { globalProps } from '../utilities/globalProps'
5
+ import { GlobalProps, globalProps, globalInlineProps } from '../utilities/globalProps'
6
6
 
7
7
  type LayoutPropTypes = {
8
8
  aria?: {[key: string]: string},
@@ -19,7 +19,7 @@ type LayoutPropTypes = {
19
19
  variant?: "light" | "dark" | "gradient",
20
20
  transparent?: boolean,
21
21
  layout?: "sidebar" | "collection" | "kanban" | "content" | "masonry",
22
- }
22
+ } & GlobalProps
23
23
 
24
24
  type LayoutSideProps = {
25
25
  children: React.ReactNode[] | React.ReactNode,
@@ -159,6 +159,8 @@ const Layout = (props: LayoutPropTypes) => {
159
159
  const filteredProps = {...props}
160
160
  delete filteredProps?.position
161
161
 
162
+ const dynamicInlineProps = globalInlineProps(props)
163
+
162
164
  return (
163
165
  <div
164
166
  {...ariaProps}
@@ -171,7 +173,8 @@ const Layout = (props: LayoutPropTypes) => {
171
173
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
172
174
  //@ts-ignore
173
175
  globalProps(filteredProps)
174
- )}
176
+ )}
177
+ style={dynamicInlineProps}
175
178
  >
176
179
  {subComponentTags('Side')}
177
180
  {nonSideChildren}
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import classnames from 'classnames'
3
3
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
4
- import { globalProps } from '../utilities/globalProps'
4
+ import { globalProps, globalInlineProps } from '../utilities/globalProps'
5
5
  import OverlayPercentage from './subcomponents/_overlay_percentage'
6
6
  import OverlayToken from './subcomponents/_overlay_token'
7
7
 
@@ -39,6 +39,7 @@ const Overlay = (props: OverlayProps) => {
39
39
  const dataProps = buildDataProps(data)
40
40
  const classes = classnames(buildCss('pb_overlay'), globalProps(props), className)
41
41
  const htmlProps = buildHtmlProps(htmlOptions)
42
+ const dynamicInlineProps = globalInlineProps(props)
42
43
 
43
44
  const getPosition = () => {
44
45
  return Object.keys(layout)[0]
@@ -57,6 +58,7 @@ const Overlay = (props: OverlayProps) => {
57
58
  {...htmlProps}
58
59
  className={classes}
59
60
  id={id}
61
+ style={dynamicInlineProps}
60
62
  >
61
63
  {isSizePercentage ?
62
64
  OverlayPercentage({
@@ -2,7 +2,7 @@ import React from 'react'
2
2
  import classnames from 'classnames'
3
3
 
4
4
  import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
5
- import { globalProps } from '../utilities/globalProps'
5
+ import { globalProps, globalInlineProps } from '../utilities/globalProps'
6
6
 
7
7
  import Caption from '../pb_caption/_caption'
8
8
 
@@ -38,6 +38,7 @@ const SectionSeparator = (props: SectionSeparatorProps): React.ReactElement => {
38
38
  const dataProps = buildDataProps(data)
39
39
  const htmlProps = buildHtmlProps(htmlOptions)
40
40
  const classes = classnames(buildCss('pb_section_separator_kit', variant, orientation, lineStyle === "dashed" ? lineStyle : ""), globalProps(props), className)
41
+ const dynamicInlineProps = globalInlineProps(props)
41
42
 
42
43
  return (
43
44
 
@@ -47,6 +48,7 @@ const SectionSeparator = (props: SectionSeparatorProps): React.ReactElement => {
47
48
  {...htmlProps}
48
49
  className={classes}
49
50
  id={id}
51
+ style={dynamicInlineProps}
50
52
  >
51
53
  {
52
54
  children && children ||
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect } from 'react'
2
2
  import classnames from 'classnames'
3
3
  import { buildAriaProps, buildDataProps, buildHtmlProps } from '../utilities/props'
4
- import { globalProps, GlobalProps } from '../utilities/globalProps'
4
+ import { globalProps, GlobalProps, globalInlineProps } from '../utilities/globalProps'
5
5
  import PbTable from '.'
6
6
  import {
7
7
  TableHead,
@@ -66,6 +66,7 @@ const Table = (props: TableProps): React.ReactElement => {
66
66
  const spaceCssName = outerPadding !== 'none' ? 'space_' : ''
67
67
  const outerPaddingCss = outerPadding ? `outer_padding_${spaceCssName}${outerPadding}` : ''
68
68
  const isTableTag = tag === 'table'
69
+ const dynamicInlineProps = globalInlineProps(props)
69
70
 
70
71
  const classNames = classnames(
71
72
  'pb_table',
@@ -154,6 +155,7 @@ const Table = (props: TableProps): React.ReactElement => {
154
155
  {...htmlProps}
155
156
  className={classNames}
156
157
  id={id}
158
+ style={dynamicInlineProps}
157
159
  >
158
160
  {children}
159
161
  </table>
@@ -164,6 +166,7 @@ const Table = (props: TableProps): React.ReactElement => {
164
166
  {...htmlProps}
165
167
  className={classNames}
166
168
  id={id}
169
+ style={dynamicInlineProps}
167
170
  >
168
171
  {children}
169
172
  </div>
@@ -177,6 +180,7 @@ const Table = (props: TableProps): React.ReactElement => {
177
180
  {...htmlProps}
178
181
  className={classNames}
179
182
  id={id}
183
+ style={dynamicInlineProps}
180
184
  >
181
185
  {children}
182
186
  </table>
@@ -187,6 +191,7 @@ const Table = (props: TableProps): React.ReactElement => {
187
191
  {...htmlProps}
188
192
  className={classNames}
189
193
  id={id}
194
+ style={dynamicInlineProps}
190
195
  >
191
196
  {children}
192
197
  </div>