-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major spacing adjustment for FeatureAttributesCompact
- Loading branch information
1 parent
2f60120
commit b441a7c
Showing
77 changed files
with
553 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...tureAttributes/FeaturesAttributesContext/FeaturesAttributesContext.stories.decorators.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
128 changes: 128 additions & 0 deletions
128
src/components/FeatureAttributes/FeaturesAttributesContext/FeaturesAttributesContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
1 change: 1 addition & 0 deletions
1
src/components/FeatureAttributes/FeaturesAttributesContext/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./FeaturesAttributesContext"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.