-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * Updated & working with typescript * remove unwatend ts-no-check * Fixed misplaced label * cleaning code * Improved helpertext color for better contrast
- Loading branch information
Showing
22 changed files
with
479 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
libraries/core-react/src/TextField/HelperText/HelperText.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
libraries/core-react/src/TextField/HelperText/HelperText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import React, { ReactNode } from 'react' | ||
import styled, { css } from 'styled-components' | ||
import { Spacing, typographyTemplate } from '../../_common/templates' | ||
import { | ||
HelperTextVariantProps, | ||
helperText as tokens, | ||
} from './HelperText.token' | ||
import { useTextField } from '../context' | ||
import { Icon } from '../Icon' | ||
import type { Variants } from '../types' | ||
|
||
type VariantionProps = { | ||
variant: HelperTextVariantProps | ||
isFocused: boolean | ||
isDisabled: boolean | ||
} | ||
|
||
const Variation = ({ variant, isFocused, isDisabled }: VariantionProps) => { | ||
if (!variant) { | ||
return `` | ||
} | ||
|
||
const { focusColor, color, disabledColor } = variant | ||
|
||
if (isDisabled) { | ||
return css` | ||
color: ${disabledColor}; | ||
` | ||
} | ||
|
||
if (isFocused) { | ||
return css` | ||
color: ${focusColor}; | ||
` | ||
} | ||
|
||
return css` | ||
color: ${color}; | ||
` | ||
} | ||
|
||
type StyledProps = { | ||
spacings: Spacing | ||
} | ||
|
||
const Container = styled.div<StyledProps>` | ||
display: flex; | ||
align-items: flex-end; | ||
margin-left: ${({ spacings }) => spacings.left}; | ||
margin-top: ${({ spacings }) => spacings.top}; | ||
` | ||
const Text = styled.p` | ||
margin: 0; | ||
${typographyTemplate(tokens.typography)} | ||
${Variation} | ||
` | ||
|
||
const StyledIcon = styled(Icon)<StyledProps>` | ||
margin-right: ${({ spacings }) => spacings.left}; | ||
` | ||
|
||
type Props = { | ||
/** Helper text */ | ||
helperText?: string | ||
/** Icon */ | ||
icon?: ReactNode | ||
/** Disabled */ | ||
disabled?: boolean | ||
/** Variant */ | ||
variant: Variants | ||
} | ||
|
||
const HelperText = React.forwardRef<HTMLDivElement, Props>( | ||
function TextFieldHelperText(props, ref) { | ||
const { | ||
helperText, | ||
icon, | ||
variant = 'default', | ||
disabled: isDisabled, | ||
} = props | ||
const helperVariant = tokens[variant] | ||
const spacings = tokens.spacings.comfortable | ||
|
||
const { isFocused } = useTextField() | ||
|
||
const iconProps = { | ||
spacings, | ||
isDisabled, | ||
color: helperVariant.color, | ||
disabledColor: helperVariant.disabledColor, | ||
focusColor: helperVariant.focusColor, | ||
} | ||
|
||
return ( | ||
<Container ref={ref} {...props} spacings={spacings}> | ||
{icon && <StyledIcon {...iconProps}>{icon}</StyledIcon>} | ||
<Text | ||
variant={helperVariant} | ||
isFocused={isFocused} | ||
isDisabled={isDisabled} | ||
> | ||
{helperText} | ||
</Text> | ||
</Container> | ||
) | ||
}, | ||
) | ||
|
||
HelperText.displayName = 'eds-text-field-helperText' | ||
|
||
export { HelperText } |
1 change: 0 additions & 1 deletion
1
...e-react/src/TextField/HelperText/index.js → ...e-react/src/TextField/HelperText/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
// @ts-nocheck | ||
export { HelperText } from './HelperText' |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.