diff --git a/packages/fannypack/package.json b/packages/fannypack/package.json index 7af00c09d..43d60fd58 100644 --- a/packages/fannypack/package.json +++ b/packages/fannypack/package.json @@ -7,7 +7,7 @@ "unpkg": "dist/fannypack.min.js", "types": "ts/index.d.ts", "scripts": { - "build": "yarn clean && yarn build:lib && yarn build:types", + "build": "yarn clean && yarn build:lib", "build:lib": "rollup -c", "build:types": "tsc --emitDeclarationOnly", "clean": "rimraf es/ lib/ dist/ ts/", @@ -83,5 +83,5 @@ "accessible", "composable" ], - "gitHead": "613d46b6624167b65e548fe917ecfb5a9a0e2dbe" + "gitHead": "7b7ed3a0783df48486e43e6937f33240a8240167" } diff --git a/packages/fannypack/src/Checkbox/styled.ts b/packages/fannypack/src/Checkbox/styled.ts index 3d857319e..7eef9ac89 100644 --- a/packages/fannypack/src/Checkbox/styled.ts +++ b/packages/fannypack/src/Checkbox/styled.ts @@ -7,6 +7,7 @@ import HiddenInput from '../_utils/HiddenInput'; import { LocalCheckboxProps } from './Checkbox'; export const CheckboxIcon = styled(Box)<{ state?: string }>` + background-color: white; border: 1px solid #bdbdbd; box-shadow: inset 0px 1px 2px #e5e5e5; border-radius: 0.2em; diff --git a/packages/fannypack/src/FieldWrapper/FieldWrapper.tsx b/packages/fannypack/src/FieldWrapper/FieldWrapper.tsx index d0622a1c6..0ee8e43f1 100644 --- a/packages/fannypack/src/FieldWrapper/FieldWrapper.tsx +++ b/packages/fannypack/src/FieldWrapper/FieldWrapper.tsx @@ -1,10 +1,29 @@ import * as React from 'react'; import * as PropTypes from 'prop-types'; import { FieldProps as ReakitFieldProps } from 'reakit/ts/Field/Field'; +// @ts-ignore +import _omit from 'lodash/omit'; +// @ts-ignore +import _get from 'lodash/get'; import { Box, Flex } from '../primitives'; +import Button from '../Button'; +import Icon from '../Icon'; +import Popover from '../Popover'; +import { LocalPopoverProps, popoverPropTypes } from '../Popover/Popover'; +import Text from '../Text'; +import VisuallyHidden from '../VisuallyHidden'; +import { withTheme } from '../styled'; import { Omit } from '../types'; -import _FieldWrapper, { Label, DescriptionText, HintText, OptionalText, ValidationText } from './styled'; +import _FieldWrapper, { + Label, + DescriptionText, + HintText, + OptionalText, + RequiredText, + TooltipPopover, + ValidationText +} from './styled'; export type LocalFieldWrapperProps = { a11yId?: string; @@ -16,6 +35,9 @@ export type LocalFieldWrapperProps = { isRequired?: boolean; label?: string | React.ReactElement; state?: string; + tooltip?: string | React.ReactElement; + tooltipPopoverProps?: Omit, 'content'>; + tooltipTrigger?: React.ReactElement; validationText?: string; }; export type FieldWrapperProps = Omit & LocalFieldWrapperProps; @@ -35,17 +57,43 @@ export const FieldWrapper: React.FunctionComponent = ({ isRequired, label, state, + tooltip, + tooltipPopoverProps: _tooltipPopoverProps, + tooltipTrigger: _tooltipTrigger, validationText, ...props }) => { + const tooltipPopoverProps = _get( + props, + 'theme.fannypack.FieldWrapper.defaultProps.tooltipPopoverProps', + _tooltipPopoverProps + ); + const tooltipTrigger = _get(props, 'theme.fannypack.FieldWrapper.defaultProps.tooltipTrigger', _tooltipTrigger); const elementProps: FieldElementProps = { isRequired, a11yId, state }; return ( <_FieldWrapper {...props}> {label && ( - + {typeof label === 'string' ? : label} {isOptional && OPTIONAL} + {isRequired && *} + {tooltip && ( + {tooltip} : tooltip} + gutter={4} + {...tooltipPopoverProps} + > + {tooltipTrigger || ( + + )} + + )} {typeof description === 'string' ? ( {description} @@ -76,6 +124,9 @@ export const fieldWrapperPropTypes = { isRequired: PropTypes.bool, label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), state: PropTypes.string, + tooltip: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), + tooltipPopoverProps: PropTypes.shape(_omit(popoverPropTypes, 'children', 'content')), + tooltipTrigger: PropTypes.element, validationText: PropTypes.string }; FieldWrapper.propTypes = fieldWrapperPropTypes; @@ -89,10 +140,13 @@ export const fieldWrapperDefaultProps = { isRequired: undefined, label: undefined, state: undefined, + tooltip: undefined, + tooltipPopoverProps: undefined, + tooltipTrigger: undefined, validationText: undefined }; FieldWrapper.defaultProps = fieldWrapperDefaultProps; // @ts-ignore -const C: React.FunctionComponent = FieldWrapper; +const C: React.FunctionComponent = withTheme(FieldWrapper); export default C; diff --git a/packages/fannypack/src/FieldWrapper/styled.ts b/packages/fannypack/src/FieldWrapper/styled.ts index e5ccd763b..5cd7a0470 100644 --- a/packages/fannypack/src/FieldWrapper/styled.ts +++ b/packages/fannypack/src/FieldWrapper/styled.ts @@ -5,6 +5,7 @@ import styled, { space } from '../styled'; import { Omit } from '../types'; // @ts-ignore import _Label from '../Label'; +import Popover from '../Popover'; // @ts-ignore import _Text from '../Text'; import { FieldWrapperProps } from './FieldWrapper'; @@ -47,6 +48,24 @@ export const OptionalText = styled(_Text)` } `; +export const RequiredText = styled(_Text)` + color: ${palette('danger')}; + margin-left: ${space(1)}rem; + line-height: 1; + + & { + ${theme('fannypack.FieldWrapper.required')}; + } +`; + +export const TooltipPopover = styled(Popover)` + padding: ${space(1, 'major')}rem; + + & { + ${theme('fannypack.FieldWrapper.TooltipPopover.base')}; + } +`; + export const ValidationText = styled(_Text)` display: block; font-size: 0.8rem; diff --git a/packages/fannypack/src/Input/Input.tsx b/packages/fannypack/src/Input/Input.tsx index a341cd079..e90da2b20 100644 --- a/packages/fannypack/src/Input/Input.tsx +++ b/packages/fannypack/src/Input/Input.tsx @@ -1,6 +1,8 @@ import * as React from 'react'; import * as PropTypes from 'prop-types'; import { InputProps as ReakitInputProps } from 'reakit/ts'; +// @ts-ignore +import _omit from 'lodash/omit'; import { InlineFlex } from '../primitives'; import { Omit, Size, sizePropType } from '../types'; @@ -20,10 +22,10 @@ export type LocalInputProps = { children?: React.ReactNode; className?: string; /** Default value of the input */ - defaultValue?: string; + defaultValue?: string | string[]; /** Disables the input */ disabled?: boolean; - inputProps?: ReakitInputProps; + inputProps?: Omit; inputRef?: React.RefObject; /** Adds a cute loading indicator to the input field */ isLoading?: boolean; @@ -34,11 +36,11 @@ export type LocalInputProps = { /** Alters the size of the input. Can be "small", "medium" or "large" */ size?: Size; /** The maximum (numeric or date-time) value for the input. Must not be less than its minimum (min attribute) value. */ - max?: number; + max?: number | string; /** If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in UTF-16 code units) that the user can enter. For other control types, it is ignored. */ maxLength?: number; /** The minimum (numeric or date-time) value for this input, which must not be greater than its maximum (max attribute) value. */ - min?: number; + min?: number | string; /** If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in UTF-16 code points) that the user can enter. For other control types, it is ignored. */ minLength?: number; /** This prop indicates whether the user can enter more than one value. This attribute only applies when the type attribute is set to email or file. */ @@ -52,13 +54,13 @@ export type LocalInputProps = { /** Setting the value of this attribute to true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked. */ spellCheck?: boolean; /** Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set. */ - step?: number; + step?: number | string; /** State of the input. Can be any color in the palette. */ state?: string; /** Specify the type of input. */ type?: string; /** Value of the input */ - value?: string; + value?: string | number | string[]; /** Function to invoke when focus is lost */ onBlur?: React.FocusEventHandler; /** Function to invoke when input has changed */ @@ -145,7 +147,7 @@ export const Input: React.FunctionComponent & InputComponents = styledSize={size} type={type} value={value} - {...inputProps} + {..._omit(inputProps, 'size')} /> {isLoading && } diff --git a/packages/fannypack/src/Radio/styled.ts b/packages/fannypack/src/Radio/styled.ts index db50aa37c..52cde69f5 100644 --- a/packages/fannypack/src/Radio/styled.ts +++ b/packages/fannypack/src/Radio/styled.ts @@ -9,6 +9,7 @@ import { RadioProps, LocalRadioProps } from './Radio'; export const RadioIcon = styled(Box)<{ state?: string }>` border: 1px solid #bdbdbd; + background-color: white; box-shadow: inset 0px 1px 2px #e5e5e5; border-radius: 100%; height: 1em; diff --git a/packages/fannypack/src/Select/Select.tsx b/packages/fannypack/src/Select/Select.tsx index 05e322eeb..36a94297b 100644 --- a/packages/fannypack/src/Select/Select.tsx +++ b/packages/fannypack/src/Select/Select.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import * as PropTypes from 'prop-types'; import { InlineBlockProps as ReakitInlineBlockProps } from 'reakit/ts/InlineBlock/InlineBlock'; +import { InputProps as ReakitInputProps } from 'reakit/ts/Input/Input'; import { InlineBlock } from '../primitives'; import { Omit } from '../types'; @@ -33,7 +34,7 @@ export type LocalSelectProps = { options: Array<{ label: string; value: string; disabled?: boolean }>; /** Hint text to display */ placeholder?: string; - selectProps: ReakitInputProps; + selectProps?: ReakitInputProps; /** Alters the size of the select field. Can be "small", "medium" or "large" */ size?: string; /** State of the select field. Can be any color in the palette. */ @@ -161,7 +162,11 @@ export class Select extends React.PureComponent { value={value} {...selectProps} > - {placeholder && } + {placeholder && ( + + )} {options.map((option, i) => (