Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MoneyInput,NumericInput,TextInput): expose CSS class to allow styling elements #1027

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 51 additions & 63 deletions packages/react/src/components/money-input/money-input.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CurrencyInput Component matches snapshot (en-CA) 1`] = `
.c1 {
.c0 {
margin: 0 0 var(--spacing-3x);
}

.c1 input,
.c1 select,
.c1 textarea {
.c0 input,
.c0 select,
.c0 textarea {
border-color: #60666E;
}

.c1 > :nth-child(0) {
.c0 > :nth-child(0) {
margin-bottom: var(--spacing-half);
}

Expand Down Expand Up @@ -111,46 +111,42 @@ exports[`CurrencyInput Component matches snapshot (en-CA) 1`] = `
outline-offset: -2px;
}

.c0 input {
.c1 .eds-TextInput-control {
text-align: left;
width: 132px;
}

<div
class="c0"
class="c0 c1"
data-testid="field-container"
>
<div
class="c1"
data-testid="field-container"
class="c2 eds-TextInput-control"
>
<div
class="c2"
>
<input
class="c3"
data-testid="text-input"
id="uuid1"
inputmode="numeric"
type="text"
value="$100.00"
/>
</div>
<input
class="c3"
data-testid="text-input"
id="uuid1"
inputmode="numeric"
type="text"
value="$100.00"
/>
</div>
</div>
`;

exports[`CurrencyInput Component matches snapshot (en-US) 1`] = `
.c1 {
.c0 {
margin: 0 0 var(--spacing-3x);
}

.c1 input,
.c1 select,
.c1 textarea {
.c0 input,
.c0 select,
.c0 textarea {
border-color: #60666E;
}

.c1 > :nth-child(0) {
.c0 > :nth-child(0) {
margin-bottom: var(--spacing-half);
}

Expand Down Expand Up @@ -250,46 +246,42 @@ exports[`CurrencyInput Component matches snapshot (en-US) 1`] = `
outline-offset: -2px;
}

.c0 input {
.c1 .eds-TextInput-control {
text-align: left;
width: 132px;
}

<div
class="c0"
class="c0 c1"
data-testid="field-container"
>
<div
class="c1"
data-testid="field-container"
class="c2 eds-TextInput-control"
>
<div
class="c2"
>
<input
class="c3"
data-testid="text-input"
id="uuid1"
inputmode="numeric"
type="text"
value="$100.00"
/>
</div>
<input
class="c3"
data-testid="text-input"
id="uuid1"
inputmode="numeric"
type="text"
value="$100.00"
/>
</div>
</div>
`;

exports[`CurrencyInput Component matches snapshot (fr-CA) 1`] = `
.c1 {
.c0 {
margin: 0 0 var(--spacing-3x);
}

.c1 input,
.c1 select,
.c1 textarea {
.c0 input,
.c0 select,
.c0 textarea {
border-color: #60666E;
}

.c1 > :nth-child(0) {
.c0 > :nth-child(0) {
margin-bottom: var(--spacing-half);
}

Expand Down Expand Up @@ -389,30 +381,26 @@ exports[`CurrencyInput Component matches snapshot (fr-CA) 1`] = `
outline-offset: -2px;
}

.c0 input {
.c1 .eds-TextInput-control {
text-align: left;
width: 132px;
}

<div
class="c0"
class="c0 c1"
data-testid="field-container"
>
<div
class="c1"
data-testid="field-container"
class="c2 eds-TextInput-control"
>
<div
class="c2"
>
<input
class="c3"
data-testid="text-input"
id="uuid1"
inputmode="numeric"
type="text"
value="100,00 $"
/>
</div>
<input
class="c3"
data-testid="text-input"
id="uuid1"
inputmode="numeric"
type="text"
value="100,00 $"
/>
</div>
</div>
`;
47 changes: 23 additions & 24 deletions packages/react/src/components/money-input/money-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import styled from 'styled-components';
import { useDataAttributes } from '../../hooks/use-data-attributes';
import { useTranslation } from '../../i18n/use-translation';
import { formatCurrency } from '../../utils/currency';
import { TextInput } from '../text-input/text-input';
import { TextInput, textInputClasses } from '../text-input';

type TextAlignment = 'left' | 'right';

const InputWrapper = styled.div<{ $textAlignment: TextAlignment }>`
input {
const StyledTextInput = styled(TextInput)<{ $textAlignment: TextAlignment }>`
.${textInputClasses.control} {
text-align: ${({ $textAlignment }) => $textAlignment};
width: 132px;
}
Expand All @@ -24,7 +24,7 @@ function safeFormatCurrency(
}

interface Props {
id?: string
id?: string;
className?: string;
disabled?: boolean;
required?: boolean;
Expand Down Expand Up @@ -145,25 +145,24 @@ export const MoneyInput: VoidFunctionComponent<Props> = ({
}, []);

return (
<InputWrapper $textAlignment={textAlignment}>
<TextInput
id={providedId}
className={className}
required={required}
disabled={disabled}
ref={inputElement}
type="text"
inputMode="numeric"
value={displayValue}
label={label}
onChange={handleChangeEvent}
onBlur={handleBlurEvent}
onFocus={handleFocusEvent}
validationErrorMessage={validationErrorMessage || t('validationErrorMessage')}
hint={hint}
noMargin={noMargin}
{...dataAttributes /* eslint-disable-line react/jsx-props-no-spreading */}
/>
</InputWrapper>
<StyledTextInput
$textAlignment={textAlignment}
id={providedId}
className={className}
required={required}
disabled={disabled}
ref={inputElement}
type="text"
inputMode="numeric"
value={displayValue}
label={label}
onChange={handleChangeEvent}
onBlur={handleBlurEvent}
onFocus={handleFocusEvent}
validationErrorMessage={validationErrorMessage || t('validationErrorMessage')}
hint={hint}
noMargin={noMargin}
{...dataAttributes /* eslint-disable-line react/jsx-props-no-spreading */}
/>
);
};
Loading