Skip to content

Commit

Permalink
saves
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahgm committed Dec 16, 2022
1 parent 962ca5b commit 53309ee
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 54 deletions.
6 changes: 6 additions & 0 deletions docs/src/pages/components/label.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ import { Label } from '@marigold/components';
description: 'Sets the label required.',
default: 'false',
},
{
property: 'labelWidth',
type: 'string',
description: 'Sets the label width.',
default: 'none',
},
{
property: '...',
type: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/FieldBase/FieldBase.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const Basic: ComponentStory<typeof FieldBase> = args => (
);

export const Complex: ComponentStory<typeof FieldBase> = args => (
<FieldBaseGroup space="medium">
<FieldBaseGroup labelWidth="30%">
<FieldBase {...args} label="This is my Label">
<input type="text" />
</FieldBase>
Expand Down
76 changes: 37 additions & 39 deletions packages/components/src/FieldBase/FieldBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

import { Label, LabelProps } from '../Label';
import { HelpText } from '../HelpText';
import { FieldBaseGroup, useFieldBaseGroupContext } from './FieldBaseGroup';
import { useFieldBaseGroupContext } from './FieldBaseGroup';
export interface FieldBaseProps {
children?: ReactNode;
variant?: string;
Expand Down Expand Up @@ -52,49 +52,47 @@ export const FieldBase = ({

const style = useComponentStyles('Field', { variant, size });

const { space } = useFieldBaseGroupContext();
const { labelWidth } = useFieldBaseGroupContext();

return (
<>
<Box
{...props}
__baseCSS={{
display: 'flex',
flexDirection: 'column',
width,
position: 'relative',
}}
css={style}
>
{label && (
<Label
required={required}
<Box
{...props}
__baseCSS={{
display: 'flex',
flexDirection: 'column',
width,
position: 'relative',
}}
css={style}
>
{label && (
<Label
required={required}
variant={variant}
size={size}
labelWidth={labelWidth}
{...labelProps}
{...stateProps}
>
{label}
</Label>
)}
<Box __baseCSS={{ display: 'flex', flexDirection: 'column' }}>
{children}
{hasHelpText && (
<HelpText
{...stateProps}
variant={variant}
size={size}
space={space}
{...labelProps}
{...stateProps}
>
{label}
</Label>
disabled={disabled}
description={description}
descriptionProps={descriptionProps}
error={error}
errorMessage={errorMessage}
errorMessageProps={errorMessageProps}
/>
)}
<Box __baseCSS={{ display: 'flex', flexDirection: 'column' }}>
{children}
{hasHelpText && (
<HelpText
{...stateProps}
variant={variant}
size={size}
disabled={disabled}
description={description}
descriptionProps={descriptionProps}
error={error}
errorMessage={errorMessage}
errorMessageProps={errorMessageProps}
/>
)}
</Box>
</Box>
</>
</Box>
);
};
11 changes: 7 additions & 4 deletions packages/components/src/FieldBase/FieldBaseGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, ReactNode, useContext } from 'react';

export interface FieldBaseGroupContextProps {
space?: 'small' | 'none' | 'large' | 'medium' | undefined;
labelWidth?: string;
}

export const FieldBaseGroupContext = createContext<FieldBaseGroupContextProps>(
Expand All @@ -10,12 +10,15 @@ export const FieldBaseGroupContext = createContext<FieldBaseGroupContextProps>(
export const useFieldBaseGroupContext = () => useContext(FieldBaseGroupContext);

export interface FieldBaseGroupProps {
space?: 'small' | 'none' | 'large' | 'medium' | undefined;
labelWidth?: string;
children: ReactNode;
}
export const FieldBaseGroup = ({ space, children }: FieldBaseGroupProps) => {
export const FieldBaseGroup = ({
labelWidth,
children,
}: FieldBaseGroupProps) => {
return (
<FieldBaseGroupContext.Provider value={{ space }}>
<FieldBaseGroupContext.Provider value={{ labelWidth }}>
{children}
</FieldBaseGroupContext.Provider>
);
Expand Down
14 changes: 4 additions & 10 deletions packages/components/src/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ export interface LabelProps extends ComponentProps<'label'> {
variant?: string;
size?: string;
required?: boolean;
space?: keyof typeof LABEL_SPACE;
labelWidth?: string;
}
const LABEL_SPACE = {
small: '10%',
medium: '20%',
large: '50%',
none: 'auto',
};

// Component
// ---------------
Expand All @@ -31,12 +25,11 @@ export const Label = ({
children,
variant,
size,
space = 'none',
labelWidth,
...props
}: LabelProps) => {
const styles = useComponentStyles('Label', { size, variant });

console.log(space);
return (
<Box
{...props}
Expand All @@ -46,7 +39,8 @@ export const Label = ({
aria-required={required}
__baseCSS={{
display: 'flex',
flexBasis: LABEL_SPACE[space],
flexDirection: 'row',
width: labelWidth,
}}
css={styles}
>
Expand Down
1 change: 1 addition & 0 deletions themes/theme-core/src/components/Label.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Theme } from '@marigold/components';

export const Label: Theme['components']['Label'] = {
base: {
justifyContent: 'flex-end',
fontSize: 'xxsmall',
color: 'text',
'&:disabled': {
Expand Down

0 comments on commit 53309ee

Please sign in to comment.