Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a72d3a
export typeahead utils
Michele-Masciave Apr 11, 2025
f8dc2b0
integrate placeholder fix and changelog
Michele-Masciave Apr 16, 2025
a857384
adjust typescript
Michele-Masciave Apr 16, 2025
e1267ef
prepare-pr
Michele-Masciave Apr 28, 2025
12211f1
fixed
Michele-Masciave Apr 30, 2025
92e5c21
Merge branch 'main' of https://github.com/Michele-Masciave/react-hook…
Michele-Masciave Apr 30, 2025
a9347da
Merge branch 'neolution-ch:main' into main
Michele-Masciave May 7, 2025
2987413
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 3, 2025
acad69e
Merge branch 'main' of https://github.com/Michele-Masciave/react-hook…
Michele-Masciave Jun 13, 2025
de96e5c
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 18, 2025
fbfcc8e
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 25, 2025
b5c2533
Merge branch 'main' of https://github.com/Michele-Masciave/react-hook…
Michele-Masciave Jul 7, 2025
7843d38
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jul 16, 2025
6b81771
Merge branch 'neolution-ch:main' into main
Michele-Masciave Sep 26, 2025
743acf1
Merge branch 'neolution-ch:main' into main
Michele-Masciave Sep 29, 2025
022db3c
Merge branch 'neolution-ch:main' into main
Michele-Masciave Oct 1, 2025
bbd78a7
Merge branch 'neolution-ch:main' into main
Michele-Masciave Oct 21, 2025
5d28ea3
Merge branch 'neolution-ch:main' into main
Michele-Masciave Dec 3, 2025
3e9f9a7
Merge branch 'neolution-ch:main' into main
Michele-Masciave Dec 10, 2025
814c18e
Merge branch 'neolution-ch:main' into main
Michele-Masciave Dec 15, 2025
a2108d9
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jan 8, 2026
349cd68
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jan 13, 2026
b94770b
Merge branch 'neolution-ch:main' into main
Michele-Masciave Feb 6, 2026
22cb448
Merge branch 'neolution-ch:main' into main
Michele-Masciave Feb 17, 2026
4a8cfb6
Merge branch 'neolution-ch:main' into main
Michele-Masciave Mar 3, 2026
f244435
Merge branch 'neolution-ch:main' into main
Michele-Masciave Apr 15, 2026
0aa2c1f
Merge branch 'neolution-ch:main' into main
Michele-Masciave May 8, 2026
7e81a4f
Merge branch 'neolution-ch:main' into main
Michele-Masciave Jun 3, 2026
2cd543a
solution
Michele-Masciave Sep 4, 2026
3c73413
Merge branch 'main' into feature/tooltip-node
Michele-Masciave Sep 4, 2026
de64f49
Change import to use type for FormGroupLayoutProps
Michele-Masciave Sep 4, 2026
df280b4
x
Michele-Masciave Sep 4, 2026
574fcc2
add tooltip to typeaheads
Michele-Masciave Sep 4, 2026
67c4457
just moved condition inline
Michele-Masciave Sep 7, 2026
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- support to react node for `labelToolTip`

### Changed

- Licence information added
Expand Down
2 changes: 2 additions & 0 deletions src/lib/AsyncTypeaheadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
disabled,
variant,
label,
labelToolTip,
helpText,
hideValidationMessage,
onBlur,
Expand Down Expand Up @@ -139,6 +140,7 @@ const AsyncTypeaheadInput = <T extends FieldValues>(props: AsyncTypeaheadInputPr
return (
<FormGroupLayout
name={name}
labelToolTip={labelToolTip}
label={useBootstrapStyle ? label : undefined}
labelStyle={useBootstrapStyle ? { color: "#8493A5", fontSize: 14 } : undefined}
layout="muiInput"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/FormGroupLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const FormGroupLayout = <T extends FieldValues, TRenderAddon = unknown>(props: F
labelStyle={labelStyle}
fieldName={props.name}
fieldId={id}
tooltip={labelToolTip}
labelToolTip={labelToolTip}
layout={layout}
/>
{switchLayout || checkboxLayout || muiInputLayout ? (
Expand Down
83 changes: 48 additions & 35 deletions src/lib/FormGroupLayoutLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
import { CSSProperties, ReactNode } from "react";
import { useFormContext } from "./context/FormContext";
import { FieldPath, FieldValues } from "react-hook-form";
import { Label, UncontrolledTooltip } from "@neolution-ch/reactstrap";
import { getRequiredLabel } from "./helpers/form";
import type { FormGroupLayoutProps } from "./FormGroupLayout";

interface FormGroupLayoutLabelProps<T extends FieldValues> {
label: ReactNode;
tooltip?: ReactNode;
type TooltipProps<T extends FieldValues> = Pick<FormGroupLayoutLabelProps<T>, "labelToolTip" | "fieldId">;

const Tooltip = <T extends FieldValues>(props: TooltipProps<T>) => {
const { fieldId, labelToolTip } = props;

if (!labelToolTip) {
return null;
}

if (typeof labelToolTip !== "string") {
return labelToolTip;
}

return (
<>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
id={`Tooltip-${fieldId}`}
className="tooltip--icon"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9 5.25h.008v.008H12v-.008z"
/>
</svg>
<UncontrolledTooltip placement="top" target={`Tooltip-${fieldId}`}>
{labelToolTip}
</UncontrolledTooltip>
</>
);
};

interface FormGroupLayoutLabelProps<T extends FieldValues> extends Pick<
FormGroupLayoutProps<T, unknown>,
"labelToolTip" | "layout" | "labelStyle" | "label"
> {
fieldName: FieldPath<T>;
fieldId: string;
layout?: "checkbox" | "switch" | "muiInput";
labelStyle?: CSSProperties;
}

const FormGroupLayoutLabel = <T extends FieldValues>(props: FormGroupLayoutLabelProps<T>) => {
const { label, tooltip, fieldName, layout, fieldId, labelStyle } = props;
const { label, labelToolTip, fieldName, layout, fieldId, labelStyle } = props;
const { requiredFields } = useFormContext<T>();

if (!label && !!tooltip) {
if (!label && !!labelToolTip) {
throw new Error("You can't have a tooltip without a label");
}

Expand All @@ -30,33 +66,10 @@ const FormGroupLayoutLabel = <T extends FieldValues>(props: FormGroupLayoutLabel
const checkboxLayout = layout === "checkbox";

return (
<>
<Label check={checkboxLayout || switchLayout} for={fieldId} style={labelStyle}>
{finalLabel}
{tooltip && (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
id={`Tooltip-${fieldId}`}
className="tooltip--icon"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9 5.25h.008v.008H12v-.008z"
/>
</svg>
)}
</Label>
{tooltip && (
<UncontrolledTooltip placement="top" target={`Tooltip-${fieldId}`}>
{tooltip}
</UncontrolledTooltip>
)}
</>
<Label check={checkboxLayout || switchLayout} for={fieldId} style={labelStyle}>
{finalLabel}
<Tooltip<T> labelToolTip={labelToolTip} fieldId={fieldId} />
</Label>
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/lib/StaticTypeaheadInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
disabled,
variant,
label,
labelToolTip,
helpText,
hideValidationMessage,
onChange,
Expand Down Expand Up @@ -112,6 +113,7 @@ const StaticTypeaheadInput = <T extends FieldValues>(props: StaticTypeaheadInput
return (
<FormGroupLayout
name={name}
labelToolTip={labelToolTip}
label={useBootstrapStyle ? label : undefined}
labelStyle={useBootstrapStyle ? { color: "#8493A5", fontSize: 14 } : undefined}
layout="muiInput"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/CommonInputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface CommonInputProps<T extends FieldValues, TRenderAddon = unknown> {
id?: string;
helpText?: ReactNode;
disabled?: boolean;
labelToolTip?: string;
labelToolTip?: ReactNode;
Comment thread
Michele-Masciave marked this conversation as resolved.
markAllOnFocus?: boolean;
inputOnly?: boolean;

Expand Down
Loading