Skip to content

Commit

Permalink
Major spacing adjustment for FeatureAttributesCompact
Browse files Browse the repository at this point in the history
  • Loading branch information
lancegliser committed Jun 19, 2024
1 parent 2f60120 commit b441a7c
Show file tree
Hide file tree
Showing 77 changed files with 553 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from "@storybook/react";
import { FeatureAttributeSample } from "./FeatureAttributeSample";
import { getFeaturesAttributesContextDecorator } from "../FeaturesAttributesContext/FeaturesAttributesContext.stories.decorators";

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta: Meta<typeof FeatureAttributeSample> = {
Expand All @@ -10,6 +11,7 @@ const meta: Meta<typeof FeatureAttributeSample> = {
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
layout: "centered",
},
decorators: [getFeaturesAttributesContextDecorator()],
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {},
args: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import { getFormProviderDecorator, withPadding } from "@/storybook";
import { FeatureAttributesConfiguration } from "./FeatureAttributesConfiguration";
import { type FeatureAttributesFieldsValues } from "./constants";
import { getFeaturesAttributesContextDecorator } from "../FeaturesAttributesContext/FeaturesAttributesContext.stories.decorators";

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta: Meta<typeof FeatureAttributesConfiguration> = {
Expand All @@ -14,6 +15,7 @@ const meta: Meta<typeof FeatureAttributesConfiguration> = {
},
decorators: [
getFormProviderDecorator<FeatureAttributesFieldsValues>(),
getFeaturesAttributesContextDecorator(),
withPadding,
],
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import {
import { useFormValues } from "@/hooks/useFormValues";
import { type FeatureAttributesFieldsValues } from "./constants";
import { formSpacingYDefault } from "@howso/react-tailwind-flowbite-components";
import { TextInputProps } from "flowbite-react";

export interface FeatureAttributesConfigurationProps extends PropsWithChildren {
className?: string;
dense?: boolean;
/** If any feature in the data has a time feature */
featuresHaveTimeFeature: boolean;
}
Expand All @@ -36,11 +34,8 @@ export interface FeatureAttributesConfigurationProps extends PropsWithChildren {
export function FeatureAttributesConfiguration({
children,
className,
dense,
featuresHaveTimeFeature,
}: FeatureAttributesConfigurationProps) {
const sizing: TextInputProps["sizing"] = dense ? "sm" : undefined;

const values = useFormValues<FeatureAttributesFieldsValues>();
const {
type: featureType,
Expand All @@ -55,17 +50,11 @@ export function FeatureAttributesConfiguration({

return (
<div className={twMerge(formSpacingYDefault, className)}>
<FeatureAttributeTypeField sizing={sizing} />
<FeatureAttributeDataTypeField
featureType={featureType}
sizing={sizing}
/>
<FeatureAttributeTypeField />
<FeatureAttributeDataTypeField featureType={featureType} />

<FeatureAttributeDateTimeFormatField
dataType={dataType}
sizing={sizing}
/>
<FeatureAttributeLocaleField dataType={dataType} sizing={sizing} />
<FeatureAttributeDateTimeFormatField dataType={dataType} />
<FeatureAttributeLocaleField dataType={dataType} />

<FeatureAttributeIsSensitiveField
featureType={featureType}
Expand All @@ -75,7 +64,6 @@ export function FeatureAttributesConfiguration({
featureType={featureType}
dataType={dataType}
nonSensitive={nonSensitive}
sizing={sizing}
/>

<FeatureAttributeIdFeatureField
Expand All @@ -90,14 +78,12 @@ export function FeatureAttributesConfiguration({
<FeatureAttributeObservationalErrorField
featureType={featureType}
dataType={dataType}
sizing={sizing}
/>

<FeatureAttributesBoundsGroup
featureType={featureType}
dataType={dataType}
dateTimeFormat={dateTimeFormat}
sizing={sizing}
/>
<FeatureAttributeNullIsDependentField
dependentFeatures={dependentFeatures}
Expand All @@ -111,16 +97,14 @@ export function FeatureAttributesConfiguration({
timeSeriesLags={timeSeries?.lags}
timeSeriesOrder={timeSeries?.order}
timeSeriesType={timeSeries?.type}
sizing={sizing}
/>

<FeatureAttributesContinuousNumbersGroup
featureType={featureType}
dataType={dataType}
sizing={sizing}
/>

<FeatureAttributesProgrammableGroup sizing={sizing} />
<FeatureAttributesProgrammableGroup />
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type FeatureAttributesTimeFeatureAtom,
} from "../hooks";
import { FeaturesAttributesDependencies } from "../FeaturesAttributesDependencies";
import { FeaturesAttributesContextProvider } from "../FeaturesAttributesContext";

export type FeaturesAttributesCompactProps = {
activeFeatureAtom: FeatureAttributesActiveFeatureAtom;
Expand Down Expand Up @@ -67,7 +68,7 @@ export const FeaturesAttributesCompact: FC<FeaturesAttributesCompactProps> = (
const [areConfigurationsDirty, setAreConfigurationsDirty] = useState(false);

return (
<ErrorBoundary>
<FeaturesAttributesContextProvider compact>
<Header
activeFeatureAtom={activeFeatureAtom}
areConfigurationsDirty={areConfigurationsDirty}
Expand All @@ -94,7 +95,7 @@ export const FeaturesAttributesCompact: FC<FeaturesAttributesCompactProps> = (
setAreConfigurationsDirty={setAreConfigurationsDirty}
/>
)}
</ErrorBoundary>
</FeaturesAttributesContextProvider>
);
};

Expand Down Expand Up @@ -139,6 +140,8 @@ const Header: FC<HeaderProps> = ({
required
label={t(translations.header.fields.feature.label)}
labelInline
// labelProps={{ className: "w-40" }}
sizing={"sm"}
name="feature"
onChange={async (event) => {
setActiveFeature(event.target.value);
Expand Down Expand Up @@ -172,6 +175,7 @@ const Header: FC<HeaderProps> = ({
<div className="flex items-end">
<Button
color={"light"}
size={"sm"}
disabled={!features.length}
onClick={toggleIsMappingOpen}
>
Expand Down Expand Up @@ -211,7 +215,7 @@ const Configuration: FC<ConfigurationProps> = (props) => {
<section data-testid="configuration-container">
<header className="mb-2 flex gap-4 items-baseline justify-between">
<div className="flex gap-1 items-center">
<h3 className="text-xl">
<h3 className="text-lg">
{t(translations.actions.configureName, {
name: activeFeature,
})}
Expand Down Expand Up @@ -295,7 +299,6 @@ const Form: FC<ConfigurationProps> = ({
>
<ErrorBoundary>
<FeatureAttributesConfiguration
dense
featuresHaveTimeFeature={!!timeFeature}
/>
</ErrorBoundary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Decorator } from "@storybook/react";
import {
FeaturesAttributesContextProvider,
FeaturesAttributesContextProviderProps,
} from "./FeaturesAttributesContext";

export const getFeaturesAttributesContextDecorator =
(props?: FeaturesAttributesContextProviderProps): Decorator =>
(Story) => {
return (
<FeaturesAttributesContextProvider {...props}>
<Story />
</FeaturesAttributesContextProvider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {
ErrorBoundary,
FieldSelectProps,
FieldTextAreaProps,
FieldTextProps,
FieldToggleProps,
} from "@howso/react-tailwind-flowbite-components";
import {
ComponentProps,
Context,
FC,
ReactNode,
createContext,
useMemo,
} from "react";
import { twMerge } from "tailwind-merge";
import { FeatureAttributesGroupBaseProps } from "../groups";

export type IFeaturesAttributesContext = {
fieldCheckboxProps?: Partial<FieldToggleProps>;
fieldSelectProps?: Pick<FieldSelectProps, "labelInline" | "labelProps">;
fieldTextProps?: Pick<FieldTextProps, "labelInline" | "labelProps">;
fieldStackProps?: {
stackProps?: ComponentProps<"div">;
} & Pick<IFeaturesAttributesContext, "fieldTextProps">;
fieldTextAreaProps?: Pick<FieldTextAreaProps, "labelInline" | "labelProps">;
fieldToggleProps?: Partial<FieldToggleProps>;
groupBaseProps?: Omit<
FeatureAttributesGroupBaseProps,
"title" | "basic" | "advanced" | "isAdvancedOpen"
>;
};

export const FeaturesAttributesContext: Context<IFeaturesAttributesContext> =
createContext({});

export type FeaturesAttributesContextProviderProps = {
children: ReactNode;
compact?: boolean;
};
export const FeaturesAttributesContextProvider: FC<
FeaturesAttributesContextProviderProps
> = ({ children, compact }) => {
const fieldCheckboxProps: IFeaturesAttributesContext["fieldCheckboxProps"] =
useMemo(() => ({}), []);
const fieldSelectProps: IFeaturesAttributesContext["fieldSelectProps"] =
useMemo(
() => ({
labelInline: compact,
labelProps: compact
? { className: twMerge(inlineLabelClassName) }
: undefined,
sizing: compact ? compactFieldSize : undefined,
}),
[compact],
);
const fieldTextProps: IFeaturesAttributesContext["fieldTextProps"] = useMemo(
() => ({
labelInline: compact,
labelProps: compact
? { className: twMerge(inlineLabelClassName) }
: undefined,
sizing: compact ? compactFieldSize : undefined,
}),
[compact],
);
const fieldTextAreaProps: IFeaturesAttributesContext["fieldTextAreaProps"] =
useMemo(
() => ({
labelInline: compact,
labelProps: compact
? { className: twMerge(inlineLabelClassName) }
: undefined,
sizing: compact ? compactFieldSize : undefined,
}),
[compact],
);
const fieldToggleProps: IFeaturesAttributesContext["fieldToggleProps"] =
useMemo(() => ({}), []);

const fieldStackProps: IFeaturesAttributesContext["fieldStackProps"] =
useMemo(
() => ({
fieldTextProps: {
labelInline: compact,
labelProps: compact
? { className: twMerge(inlineLabelStackFieldClassName) }
: undefined,
sizing: compact ? compactFieldSize : undefined,
},
stackProps: compact
? { className: twMerge(inlineLabelStackClassName) }
: undefined,
}),
[compact],
);
const groupBaseProps: IFeaturesAttributesContext["groupBaseProps"] = useMemo(
() => ({
titleProps: {
className: twMerge(compact && "text-md"),
},
advancedControlProps: {
size: compact ? "sm" : undefined,
},
}),
[compact],
);

return (
<FeaturesAttributesContext.Provider
value={{
fieldCheckboxProps,
fieldSelectProps,
fieldTextProps,
fieldStackProps,
fieldTextAreaProps,
fieldToggleProps,
groupBaseProps,
}}
>
<ErrorBoundary>{children}</ErrorBoundary>
</FeaturesAttributesContext.Provider>
);
};
const inlineLabelClassName = "w-40";
const inlineLabelStackClassName = `[&_div:nth-child(1)_label]:w-40`;
const inlineLabelStackFieldClassName = "";
const compactFieldSize: FieldTextProps["sizing"] = "sm";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./FeaturesAttributesContext";
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FeatureAttributesIndex,
getFeatureAttributesIndexAtom,
} from "../hooks";
import { getFeaturesAttributesContextDecorator } from "../FeaturesAttributesContext/FeaturesAttributesContext.stories.decorators";

// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
const meta: Meta<typeof FeaturesAttributesDependencies> = {
Expand All @@ -15,6 +16,7 @@ const meta: Meta<typeof FeaturesAttributesDependencies> = {
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
layout: "centered",
},
decorators: [getFeaturesAttributesContextDecorator()],
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
argTypes: {},
args: {
Expand Down
Loading

0 comments on commit b441a7c

Please sign in to comment.