Skip to content

Commit

Permalink
Feat(web-react): Improve Docs components - add StyleProps, remove def…
Browse files Browse the repository at this point in the history
…aultProps and other minor fixes
  • Loading branch information
crishpeen committed Aug 13, 2024
1 parent d65bcf9 commit 7b3ab46
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
14 changes: 7 additions & 7 deletions packages/web-react/docs/DocsBox.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import classNames from 'classnames';
import React, { ReactNode } from 'react';
import { useStyleProps } from '../src/hooks';
import { SizesDictionaryType, StyleProps } from '../src/types';
import { SizesDictionaryType, StyleProps, useStyleProps } from '../src';

interface DocsBoxProps extends StyleProps {
children: ReactNode;
size?: SizesDictionaryType;
}

const defaultProps = {
const defaultProps: Partial<DocsBoxProps> = {
size: 'medium',
};

const DocsBox = ({ children, size, ...restProps }: DocsBoxProps) => {
const DocsBox = (props: DocsBoxProps) => {
const propsWithDefaults = { ...defaultProps, ...props };
const { children, size, ...restProps } = propsWithDefaults;
const { styleProps, props: transferProps } = useStyleProps(restProps);
const sizeClass = size ? `docs-Box--${size}` : '';

return (
<div {...styleProps} {...transferProps} className={`docs-Box ${sizeClass} ${styleProps.className}`}>
<div {...styleProps} {...transferProps} className={classNames('docs-Box', sizeClass, styleProps.className)}>
{children}
</div>
);
};

DocsBox.defaultProps = defaultProps;

export default DocsBox;
40 changes: 23 additions & 17 deletions packages/web-react/docs/DocsSections.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import React, { ReactNode } from 'react';
import { Tag } from '../src/components';
import { StyleProps, Tag, useStyleProps } from '../src';
import DocsStack from './DocsStack';

interface DocsSectionProps {
interface DocsSectionProps extends StyleProps {
children: ReactNode;
hasStack?: boolean;
stackAlignment?: 'start' | 'center' | 'end' | 'stretch';
tag?: string;
title: string;
}

const DocsSection = ({ children, hasStack = true, stackAlignment = 'start', title, tag }: DocsSectionProps) => (
<section className="UNSTABLE_Section">
<h2 className="docs-Heading">
{title}
{tag && (
<Tag color="warning" isSubtle>
{tag}
</Tag>
)}
</h2>
{hasStack ? <DocsStack stackAlignment={stackAlignment}>{children}</DocsStack> : children}
</section>
);

DocsSection.defaultProps = {
const defaultProps: Partial<DocsSectionProps> = {
hasStack: true,
stackAlignment: 'start',
tag: '',
};

const DocsSection = (props: DocsSectionProps) => {
const propsWithDefaults = { ...defaultProps, ...props };
const { children, hasStack = true, stackAlignment = 'start', title, tag, ...restProps } = propsWithDefaults;
const { styleProps, props: transferProps } = useStyleProps(restProps);

return (
<section {...styleProps} {...transferProps} className="UNSTABLE_Section">
<h2 className="docs-Heading">
{title}
{tag && (
<Tag color="warning" isSubtle>
{tag}
</Tag>
)}
</h2>
{hasStack ? <DocsStack stackAlignment={stackAlignment}>{children}</DocsStack> : children}
</section>
);
};

export default DocsSection;
23 changes: 16 additions & 7 deletions packages/web-react/docs/DocsStack.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import classNames from 'classnames';
import React, { ReactNode } from 'react';
import { StyleProps, useStyleProps } from '../src';

interface DocsStackProps {
interface DocsStackProps extends StyleProps {
children: ReactNode;
stackAlignment?: 'start' | 'center' | 'end' | 'stretch';
}

const DocsStack = ({ children, stackAlignment }: DocsStackProps) => {
const alignmentClass = stackAlignment ? `docs-Stack--${stackAlignment}` : '';

return <div className={`docs-Stack ${alignmentClass}`}>{children}</div>;
const defaultProps: Partial<DocsStackProps> = {
stackAlignment: undefined,
};

DocsStack.defaultProps = {
stackAlignment: '',
const DocsStack = (props: DocsStackProps) => {
const propsWithDefaults = { ...defaultProps, ...props };
const { children, stackAlignment, ...restProps } = propsWithDefaults;
const { styleProps, props: transferProps } = useStyleProps(restProps);
const alignmentClass = stackAlignment ? `docs-Stack--${stackAlignment}` : '';

return (
<div {...styleProps} {...transferProps} className={classNames('docs-Stack', alignmentClass)}>
{children}
</div>
);
};

export default DocsStack;

0 comments on commit 7b3ab46

Please sign in to comment.