import * as React from 'react' import styled from 'styled-components' import type { IconProps } from '@planview/pv-icons' import { theme, text } from '@planview/pv-utilities' import Asterisk from './asterisk' import Icon from './icon' type LabelProps = React.LabelHTMLAttributes & { /** Label text, generally a string */ children: React.ReactNode /** Should the asterisk be shown? Setting is ignored if requiredTooltip is provided */ required?: boolean /** Text to be shown when hovering over the asterisk */ requiredTooltip?: string /** Icon to be shown. Defaults to Help icon if iconTooltip is provided without specifying an icon */ icon?: React.ReactElement /** Text to be shown when hovering over the icon */ iconTooltip?: string /** * Determines if the label is rendered as a `label` or `span` element. Use false when * a `label` element would be semantically incorrect for your use case. */ useLabelElement?: boolean } const LabelText = styled.label` ${text.semibold}; color: var(--pvdsform__label-text, ${theme.textPrimary}); ` /** * Implementation of the [Label specification](https://design.planview.com/components/forms/form-label) * * `import { Label } from '@planview/pv-form'` */ const Label: React.FC = ({ id, children, icon, iconTooltip, required, requiredTooltip, className, useLabelElement = true, ...rest }) => (
{children} {(required || requiredTooltip) && ( )} {(icon || iconTooltip) && }
) export { Label } export default Label