Skip to content

Commit 72bc782

Browse files
committed
Support sticky tooltips in FieldInput and legend in LabelsInput
1 parent 4006a27 commit 72bc782

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

web/packages/shared/components/FieldInput/FieldInput.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const FieldInput = forwardRef<HTMLInputElement, FieldInputProps>(
5757
spellCheck,
5858
readonly = false,
5959
toolTipContent = null,
60+
tooltipSticky = false,
6061
disabled = false,
6162
markAsError = false,
6263
required = false,
@@ -114,7 +115,10 @@ const FieldInput = forwardRef<HTMLInputElement, FieldInputProps>(
114115
>
115116
{label}
116117
</span>
117-
<IconTooltip children={toolTipContent} />
118+
<IconTooltip
119+
sticky={tooltipSticky}
120+
children={toolTipContent}
121+
/>
118122
</>
119123
) : (
120124
<>{label}</>
@@ -242,6 +246,7 @@ export type FieldInputProps = BoxProps & {
242246
min?: number;
243247
max?: number;
244248
toolTipContent?: React.ReactNode;
249+
tooltipSticky?: boolean;
245250
disabled?: boolean;
246251
// markAsError is a flag to highlight an
247252
// input box as error color before validator

web/packages/teleport/src/components/LabelsInput/LabelsInput.story.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export const Custom = () => {
6060
<LabelsInput
6161
labels={labels}
6262
setLabels={setLables}
63+
legend="List of Labels"
64+
tooltipContent="List of labels, 'nuff said"
6365
labelKey={{
6466
fieldName: 'Custom Key Name',
6567
placeholder: 'custom key placeholder',

web/packages/teleport/src/components/LabelsInput/LabelsInput.tsx

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
import styled from 'styled-components';
2020

21-
import { Box, ButtonIcon, ButtonSecondary, Flex } from 'design';
21+
import { Box, ButtonIcon, ButtonSecondary, Flex, Text } from 'design';
2222
import * as Icons from 'design/Icon';
2323
import { inputGeometry } from 'design/Input/Input';
24+
import { IconTooltip } from 'design/Tooltip';
2425
import FieldInput from 'shared/components/FieldInput';
2526
import {
2627
useRule,
@@ -63,6 +64,8 @@ type LabelValidationResult = {
6364
export type LabelsRule = Rule<Label[], LabelListValidationResult>;
6465

6566
export function LabelsInput({
67+
legend,
68+
tooltipContent,
6669
labels = [],
6770
setLabels,
6871
disableBtns = false,
@@ -74,6 +77,8 @@ export function LabelsInput({
7477
inputWidth = 200,
7578
rule = defaultRule,
7679
}: {
80+
legend?: string;
81+
tooltipContent?: string;
7782
labels: Label[];
7883
setLabels(l: Label[]): void;
7984
disableBtns?: boolean;
@@ -141,15 +146,34 @@ export function LabelsInput({
141146
const width = `${inputWidth}px`;
142147
const inputSize = 'medium';
143148
return (
144-
<>
149+
<Fieldset>
150+
{legend && (
151+
<Legend>
152+
{tooltipContent ? (
153+
<>
154+
<span
155+
css={{
156+
marginRight: '4px',
157+
verticalAlign: 'middle',
158+
}}
159+
>
160+
{legend}
161+
</span>
162+
<IconTooltip children={tooltipContent} />
163+
</>
164+
) : (
165+
legend
166+
)}
167+
</Legend>
168+
)}
145169
{labels.length > 0 && (
146-
<Flex mt={2}>
170+
<Flex mt={legend ? 1 : 0} mb={1}>
147171
<Box width={width} mr="3">
148-
{labelKey.fieldName} <SmallText>(required field)</SmallText>
149-
</Box>
150-
<Box>
151-
{labelVal.fieldName} <SmallText>(required field)</SmallText>
172+
<Text typography="body3">
173+
{labelKey.fieldName} (required field)
174+
</Text>
152175
</Box>
176+
<Text typography="body3">{labelVal.fieldName} (required field)</Text>
153177
</Flex>
154178
)}
155179
<Box>
@@ -229,17 +253,12 @@ export function LabelsInput({
229253
<Icons.Add className="icon-add" disabled={disableBtns} size="small" />
230254
{labels.length > 0 ? `Add another ${adjective}` : `Add a ${adjective}`}
231255
</ButtonSecondary>
232-
</>
256+
</Fieldset>
233257
);
234258
}
235259

236260
const defaultRule = () => () => ({ valid: true });
237261

238-
const SmallText = styled.span`
239-
font-size: ${p => p.theme.fontSizes[1]}px;
240-
font-weight: lighter;
241-
`;
242-
243262
export const nonEmptyLabels: LabelsRule = labels => () => {
244263
const results = labels.map(label => ({
245264
name: requiredField('required')(label.name)(),
@@ -250,3 +269,15 @@ export const nonEmptyLabels: LabelsRule = labels => () => {
250269
results: results,
251270
};
252271
};
272+
273+
const Fieldset = styled.fieldset`
274+
border: none;
275+
margin: 0;
276+
padding: 0;
277+
`;
278+
279+
const Legend = styled.legend`
280+
margin: 0 0 ${props => props.theme.space[1]}px 0;
281+
padding: 0;
282+
${props => props.theme.typography.body3}
283+
`;

0 commit comments

Comments
 (0)