Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(web-react): Improve Docs components - add StyleProps, remove def… #1571

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/web-react/docs/DocsBox.tsx
crishpeen marked this conversation as resolved.
Show resolved Hide resolved
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
literat marked this conversation as resolved.
Show resolved Hide resolved
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
crishpeen marked this conversation as resolved.
Show resolved Hide resolved
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;
Loading