Skip to content

Commit

Permalink
feat(localized-money-input): add support for isCondensed prop on Loca… (
Browse files Browse the repository at this point in the history
#2798)

* feat(localized-money-input): add support for isCondensed prop on LocalizedMoneyInput component

* feat(localized-money-input): add spec for new isCondensed prop

---------

Co-authored-by: Carlos Cortizas <[email protected]>
  • Loading branch information
Sarah4VT and CarlosCortizasCT authored Apr 29, 2024
1 parent d72e043 commit 0798b97
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/six-timers-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-uikit/localized-money-input': minor
'@commercetools-uikit/money-input': minor
---

Add support for isCondensed property on LocalizedMoneyInput component
1 change: 1 addition & 0 deletions packages/components/inputs/localized-money-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default Example;
| `onFocus` | `Function`<br/>[See signature.](#signature-onFocus) | | | Called when input is focused |
| `hideCurrencyExpansionControls` | `boolean` | | | Will hide the currency expansion controls when set to `true`. All currencies will be shown when set to `true`. |
| `defaultExpandCurrencies` | `boolean` | | | Controls whether one or all currencirs are visible by default |
| `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
| `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
| `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
| `placeholder` | `Record` | | | Placeholder text for the input |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ storiesOf('Components|Inputs', module)
// warnings in case hideCurrencyExpansionControls is true
defaultExpandCurrencies || undefined
}
isCondensed={boolean('isCondensed', false)}
isDisabled={boolean('isDisabled', false)}
isReadOnly={boolean('isReadOnly', false)}
placeholder={object('placeholder', { EUR: '', USD: '' })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export type TLocalizedMoneyInputProps = {
* Controls whether one or all currencirs are visible by default
*/
defaultExpandCurrencies?: boolean;
/**
* Use this property to reduce the paddings of the component for a ui compact variant
*/
isCondensed?: boolean;
/**
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
*/
Expand Down Expand Up @@ -161,6 +165,10 @@ type TLocalizedInputProps = {
* Called when input is focused
*/
onFocus?: (event: TCustomEvent) => void;
/**
* Use this property to reduce the paddings of the component for a ui compact variant
*/
isCondensed?: boolean;
/**
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
*/
Expand Down Expand Up @@ -246,6 +254,7 @@ const LocalizedInput = (props: TLocalizedInputProps) => {
value={props.value}
onChange={handleChange}
onBlur={props.onBlur}
isCondensed={props.isCondensed}
isDisabled={props.isDisabled}
isReadOnly={props.isReadOnly}
placeholder={props.placeholder}
Expand Down Expand Up @@ -335,6 +344,7 @@ const LocalizedMoneyInput = (props: TLocalizedMoneyInputProps) => {
}
onBlur={props.onBlur}
onFocus={props.onFocus}
isCondensed={props.isCondensed}
isDisabled={props.isDisabled}
isReadOnly={props.isReadOnly}
hasError={Boolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ export const component = () => (
isReadOnly={true}
/>
</Spec>
<Spec label="when condensed and open">
<LocalizedMoneyInput
value={value}
onChange={() => {}}
selectedCurrency="CAD"
horizontalConstraint={7}
isCondensed={true}
defaultExpandCurrencies={true}
/>
</Spec>
<Spec label="when condensed and closed">
<LocalizedMoneyInput
value={value}
onChange={() => {}}
selectedCurrency="CAD"
horizontalConstraint={7}
isCondensed={true}
/>
</Spec>
<Spec label="when there is an error for a specific currency (first one)">
<LocalizedMoneyInput
value={value}
Expand Down
1 change: 1 addition & 0 deletions packages/components/inputs/money-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default Example;
| `placeholder` | `string` | | | Placeholder text for the input |
| `onBlur` | `Function`<br/>[See signature.](#signature-onBlur) | | | Called when input is blurred |
| `onFocus` | `Function`<br/>[See signature.](#signature-onFocus) | | | Called when input is focused |
| `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
| `isDisabled` | `boolean` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
| `isReadOnly` | `boolean` | | | Indicates that the field is displaying read-only content |
| `isAutofocussed` | `boolean` | | | Focus the input on initial render |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const getCurrencyLabelStyles = (props: TInputProps) => css`
border-right: 0;
padding: 0 ${designTokens.spacing25};
align-items: center;
font-size: ${designTokens.fontSize30};
font-size: ${props.isCondensed
? designTokens.fontSize20
: designTokens.fontSize30};
box-sizing: border-box;
&:focus-within: {
Expand Down
10 changes: 10 additions & 0 deletions packages/components/inputs/money-input/src/money-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const getPortalNode = (id?: string) =>
type TLabel = {
id: string;
children?: ReactNode;
isCondensed?: boolean;
isDisabled?: boolean;
isReadOnly?: boolean;
};
Expand Down Expand Up @@ -86,6 +87,7 @@ type TCreateCurrencySelectStyles = (
) => void;

export type TInputProps = {
isCondensed?: boolean;
isDisabled?: boolean;
hasError?: boolean;
hasWarning?: boolean;
Expand All @@ -103,6 +105,7 @@ type TBase = {
const createCurrencySelectStyles: TCreateCurrencySelectStyles = ({
hasWarning,
hasError,
isCondensed,
isDisabled,
isReadOnly,
menuPortalZIndex,
Expand All @@ -112,6 +115,7 @@ const createCurrencySelectStyles: TCreateCurrencySelectStyles = ({
hasWarning,
hasError,
menuPortalZIndex,
isCondensed,
isReadOnly,
isDisabled,
});
Expand Down Expand Up @@ -460,6 +464,10 @@ type TMoneyInputProps = {
* Called when input is focused
*/
onFocus?: (event: TCustomEvent) => void;
/**
* Use this property to reduce the paddings of the component for a ui compact variant
*/
isCondensed?: boolean;
/**
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
*/
Expand Down Expand Up @@ -709,6 +717,7 @@ const MoneyInput = (props: TMoneyInputProps) => {
const currencySelectStyles = createCurrencySelectStyles({
hasWarning: props.hasWarning,
hasError: props.hasError,
isCondensed: props.isCondensed,
isDisabled: props.isDisabled,
isReadOnly: props.isReadOnly,
menuPortalZIndex: props.menuPortalZIndex,
Expand Down Expand Up @@ -785,6 +794,7 @@ const MoneyInput = (props: TMoneyInputProps) => {
{hasNoCurrencies ? (
<CurrencyLabel
id={MoneyInput.getAmountInputId(moneyInputId) as string}
isCondensed={props.isCondensed}
isDisabled={props.isDisabled}
isReadOnly={props.isReadOnly}
>
Expand Down

0 comments on commit 0798b97

Please sign in to comment.