Skip to content

Commit

Permalink
proof of concept for advanced settings wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ehconitin committed Nov 12, 2024
1 parent b489a8f commit 3306273
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 304 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useExpandedAnimation } from '@/settings/hooks/useExpandedAnimation';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import styled from '@emotion/styled';
import { AnimatePresence, motion } from 'framer-motion';
import { useRecoilValue } from 'recoil';
import { IconTool, MAIN_COLORS } from 'twenty-ui';

const StyledAdvancedWrapper = styled.div`
position: relative;
width: 100%;
`;

const StyledIconContainer = styled.div`
border-right: 1px solid ${MAIN_COLORS.yellow};
display: flex;
height: 100%;
left: ${({ theme }) => theme.spacing(-6)};
position: absolute;
top: 0;
`;

const StyledContent = styled.div`
width: 100%;
`;
const StyledIconTool = styled(IconTool)`
margin-right: ${({ theme }) => theme.spacing(0.5)};
`;

type AdvancedSettingsWrapperProps = {
children: React.ReactNode;
dimension?: 'width' | 'height';
hideIcon?: boolean;
};

export const AdvancedSettingsWrapper = ({
children,
dimension = 'height',
hideIcon = false,
}: AdvancedSettingsWrapperProps) => {
const isAdvancedModeEnabled = useRecoilValue(isAdvancedModeEnabledState);
const { contentRef, motionAnimationVariants } = useExpandedAnimation(
isAdvancedModeEnabled,
dimension,
);

return (
<AnimatePresence>
{isAdvancedModeEnabled && (
<motion.div
ref={contentRef}
initial="initial"
animate="animate"
exit="exit"
variants={motionAnimationVariants}
>
<StyledAdvancedWrapper>
{!hideIcon && (
<StyledIconContainer>
<StyledIconTool size={12} color={MAIN_COLORS.yellow} />
</StyledIconContainer>
)}
<StyledContent>{children}</StyledContent>
</StyledAdvancedWrapper>
</motion.div>
)}
</AnimatePresence>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { useAuth } from '@/auth/hooks/useAuth';
import { billingState } from '@/client-config/states/billingState';
import { SettingsNavigationDrawerItem } from '@/settings/components/SettingsNavigationDrawerItem';
import { useExpandedHeightAnimation } from '@/settings/hooks/useExpandedHeightAnimation';
import { useExpandedAnimation } from '@/settings/hooks/useExpandedAnimation';
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
import { SettingsPath } from '@/types/SettingsPath';
import {
Expand Down Expand Up @@ -69,7 +69,7 @@ const StyledIconTool = styled(IconTool)`

export const SettingsNavigationDrawerItems = () => {
const isAdvancedModeEnabled = useRecoilValue(isAdvancedModeEnabledState);
const { contentRef, motionAnimationVariants } = useExpandedHeightAnimation(
const { contentRef, motionAnimationVariants } = useExpandedAnimation(
isAdvancedModeEnabled,
);
const { signOut } = useAuth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import { moveArrayItem } from '~/utils/array/moveArrayItem';
import { toSpliced } from '~/utils/array/toSpliced';
import { applySimpleQuotesToString } from '~/utils/string/applySimpleQuotesToString';

import { EXPANDED_WIDTH_ANIMATION_VARIANTS } from '@/settings/constants/ExpandedWidthAnimationVariants';
import { AdvancedSettingsWrapper } from '@/settings/components/AdvancedSettingsWrapper';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import { AnimatePresence, motion } from 'framer-motion';
import { useRecoilValue } from 'recoil';
import { SettingsDataModelFieldSelectFormOptionRow } from './SettingsDataModelFieldSelectFormOptionRow';

Expand Down Expand Up @@ -251,26 +250,14 @@ export const SettingsDataModelFieldSelectForm = ({
<>
<StyledContainer>
<StyledLabelContainer>
<AnimatePresence>
{isAdvancedModeEnabled && (
<motion.div
initial="initial"
animate="animate"
exit="exit"
variants={EXPANDED_WIDTH_ANIMATION_VARIANTS}
>
<StyledApiKeyContainer>
<StyledIconContainer>
<StyledIconTool
size={12}
color={MAIN_COLORS.yellow}
/>
</StyledIconContainer>
<StyledApiKey>API keys</StyledApiKey>
</StyledApiKeyContainer>
</motion.div>
)}
</AnimatePresence>
<AdvancedSettingsWrapper dimension="width" hideIcon={true}>
<StyledApiKeyContainer>
<StyledIconContainer>
<StyledIconTool size={12} color={MAIN_COLORS.yellow} />
</StyledIconContainer>
<StyledApiKey>API keys</StyledApiKey>
</StyledApiKeyContainer>
</AdvancedSettingsWrapper>
<StyledOptionsLabel
isAdvancedModeEnabled={isAdvancedModeEnabled}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { v4 } from 'uuid';

import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem';
import { EXPANDED_WIDTH_ANIMATION_VARIANTS } from '@/settings/constants/ExpandedWidthAnimationVariants';
import { AdvancedSettingsWrapper } from '@/settings/components/AdvancedSettingsWrapper';
import { OPTION_VALUE_MAXIMUM_LENGTH } from '@/settings/data-model/constants/OptionValueMaximumLength';
import { getOptionValueFromLabel } from '@/settings/data-model/fields/forms/select/utils/getOptionValueFromLabel';
import { TextInput } from '@/ui/input/components/TextInput';
Expand All @@ -25,7 +25,6 @@ import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer';
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import { AnimatePresence, motion } from 'framer-motion';
import { useRecoilValue } from 'recoil';

type SettingsDataModelFieldSelectFormOptionRowProps = {
Expand Down Expand Up @@ -111,28 +110,19 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({
stroke={theme.icon.stroke.sm}
color={theme.font.color.extraLight}
/>
<AnimatePresence>
{isAdvancedModeEnabled && (
<motion.div
initial="initial"
animate="animate"
exit="exit"
variants={EXPANDED_WIDTH_ANIMATION_VARIANTS}
>
<StyledOptionInput
value={option.value}
onChange={(input) =>
onChange({
...option,
value: getOptionValueFromLabel(input),
})
}
RightIcon={isDefault ? IconCheck : undefined}
maxLength={OPTION_VALUE_MAXIMUM_LENGTH}
/>
</motion.div>
)}
</AnimatePresence>
<AdvancedSettingsWrapper dimension="width" hideIcon={true}>
<StyledOptionInput
value={option.value}
onChange={(input) =>
onChange({
...option,
value: getOptionValueFromLabel(input),
})
}
RightIcon={isDefault ? IconCheck : undefined}
maxLength={OPTION_VALUE_MAXIMUM_LENGTH}
/>
</AdvancedSettingsWrapper>
<Dropdown
dropdownId={dropdownIds.color}
dropdownPlacement="bottom-start"
Expand Down
Loading

0 comments on commit 3306273

Please sign in to comment.