Skip to content

Commit

Permalink
docs: updating StepperField docs (aws-amplify#1169)
Browse files Browse the repository at this point in the history
* docs: updating StepperField docs

* chore: updating description
  • Loading branch information
zchenwei authored Jan 20, 2022
1 parent b4c327a commit 15d28c3
Show file tree
Hide file tree
Showing 20 changed files with 324 additions and 311 deletions.
1 change: 0 additions & 1 deletion docs/src/components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Highlight, { defaultProps } from 'prism-react-renderer';
import {
Tabs,
TabItem,
Card,
Flex,
View,
Button,
Expand Down
6 changes: 5 additions & 1 deletion docs/src/data/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export const inputComponents = [
{ href: '/components/textfield', label: 'Text Field', body: `` },
{ href: '/components/selectfield', label: 'Select Field', body: `` },
{ href: '/components/sliderfield', label: 'Slider Field', body: `` },
{ href: '/components/stepperfield', label: 'Stepper Field', body: `` },
{
href: '/components/stepperfield',
label: 'Stepper Field',
body: `A StepperField is a number input with buttons to increase or decrease the value.`,
},
{ href: '/components/searchfield', label: 'Search Field', body: `` },
{ href: '/components/passwordfield', label: 'Password Field', body: `` },
{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/alert/AlertPropControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SwitchField,
Flex,
} from '@aws-amplify/ui-react';
import React from 'react';
import * as React from 'react';

export interface AlertPropControlsProps extends AlertProps {
setVariation: (value: React.SetStateAction<AlertProps['variation']>) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export const AlertIconExample = () => {
<Alert variation="error" hasIcon={false}>
This Alert does not have an icon
</Alert>
<Alert variation="success" iconSize="large">
This Alert has a large icon
</Alert>
<Alert variation="success">This Alert has a large icon</Alert>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ export const AlertStylePropsExample = () => {
const { tokens } = useTheme();

return (
<>
<Alert
backgroundColor={tokens.colors.brand.primary[10]}
color={tokens.colors.font.primary}
fontWeight="bold"
border={`${tokens.borderWidths.large} solid ${tokens.colors.brand.primary[80]}`}
borderRadius="10px"
>
Passing props directly
</Alert>
</>
<Alert
backgroundColor={tokens.colors.brand.primary[10]}
color={tokens.colors.font.primary}
fontWeight="bold"
border={`${tokens.borderWidths.large} solid ${tokens.colors.brand.primary[80]}`}
borderRadius="10px"
>
Passing props directly
</Alert>
);
};
13 changes: 7 additions & 6 deletions docs/src/pages/components/alert/useAlertProps.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { AlertProps } from '@aws-amplify/ui-react';
import { useState } from 'react';
import * as React from 'react';

import { AlertPropControlsProps } from './AlertPropControls';

interface UseAlertProps {
(initialValues: AlertProps & { body: string }): AlertPropControlsProps;
}

export const useAlertProps: UseAlertProps = (initialValues) => {
const [variation, setVariation] = useState<AlertProps['variation']>(
const [variation, setVariation] = React.useState<AlertProps['variation']>(
initialValues.variation
);
const [isDismissible, setIsDismissible] = useState<
const [isDismissible, setIsDismissible] = React.useState<
AlertProps['isDismissible']
>(initialValues.isDismissible);
const [hasIcon, setHasIcon] = useState<AlertProps['hasIcon']>(
const [hasIcon, setHasIcon] = React.useState<AlertProps['hasIcon']>(
initialValues.hasIcon
);
const [heading, setHeading] = useState<AlertProps['heading']>(
const [heading, setHeading] = React.useState<AlertProps['heading']>(
initialValues.heading
);
const [body, setBody] = useState<string>(initialValues.body);
const [body, setBody] = React.useState<string>(initialValues.body);

return {
variation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import * as React from 'react';

import {
CheckboxField,
Flex,
StepperFieldProps,
SelectField,
TextField,
} from '@aws-amplify/ui-react';

import { DemoBox } from './DemoBox';

export interface StepperFieldPropControlsProps extends StepperFieldProps {
setVariation: (
value: React.SetStateAction<StepperFieldProps['variation']>
Expand Down Expand Up @@ -40,7 +39,7 @@ export const StepperFieldPropControls: React.FC<StepperFieldPropControlsProps> =
variation,
setVariation,
}) => (
<DemoBox primitiveName="StepperField">
<Flex direction="column">
<TextField
label="label"
value={label as string}
Expand Down Expand Up @@ -100,5 +99,5 @@ export const StepperFieldPropControls: React.FC<StepperFieldPropControlsProps> =
onChange={(event) => setLabelHidden(event.target.checked)}
label="labelHidden"
/>
</DemoBox>
</Flex>
);
59 changes: 40 additions & 19 deletions docs/src/pages/components/stepperfield/demo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import * as React from 'react';

import { Flex, StepperField } from '@aws-amplify/ui-react';
import { StepperField } from '@aws-amplify/ui-react';

import { StepperFieldPropControls } from '@/components/StepperFieldPropControls';
import { useStepperFieldProps } from '@/components/useStepperFieldProps';
import { Example } from '@/components/Example';
import { Demo } from '@/components/Demo';
import {
StepperFieldPropControls,
StepperFieldPropControlsProps,
} from './StepperFieldPropControls';
import { useStepperFieldProps } from './useStepperFieldProps';

const propsToCode = (props: StepperFieldPropControlsProps) => {
return (
`<StepperField
max={${props.max}}
min={${props.min}}
step={${props.step}}` +
(props.variation
? `\n variation=${JSON.stringify(props.variation)}`
: '') +
(props.size ? `\n size="${props.size}"` : '') +
`
label="${props.label}"` +
(props.labelHidden ? `\n labelHidden=${props.labelHidden}` : '') +
`
/>`
);
};

export const StepperFieldDemo = () => {
const stepperFieldProps = useStepperFieldProps({
Expand All @@ -16,20 +37,20 @@ export const StepperFieldDemo = () => {
});

return (
<Flex direction="column">
<StepperFieldPropControls {...stepperFieldProps} />
<Example>
<StepperField
label={stepperFieldProps.label}
defaultValue={stepperFieldProps.defaultValue}
max={stepperFieldProps.max}
min={stepperFieldProps.min}
size={stepperFieldProps.size}
variation={stepperFieldProps.variation}
step={stepperFieldProps.step}
labelHidden={stepperFieldProps.labelHidden}
/>
</Example>
</Flex>
<Demo
code={propsToCode(stepperFieldProps)}
propControls={<StepperFieldPropControls {...stepperFieldProps} />}
>
<StepperField
label={stepperFieldProps.label}
defaultValue={stepperFieldProps.defaultValue}
max={stepperFieldProps.max}
min={stepperFieldProps.min}
size={stepperFieldProps.size}
variation={stepperFieldProps.variation}
step={stepperFieldProps.step}
labelHidden={stepperFieldProps.labelHidden}
/>
</Demo>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

import { StepperField } from '@aws-amplify/ui-react';

export const ControlledStepperField = () => {
export const ControlledStepperFieldExample = () => {
const [value, setValue] = React.useState(0);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { StepperField } from '@aws-amplify/ui-react';

export const DefaultStepperFieldExample = () => {
return (
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
labelHidden
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { StepperField } from '@aws-amplify/ui-react';

export const DisabledStepperFieldExample = () => {
return (
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
labelHidden
isDisabled
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { StepperField } from '@aws-amplify/ui-react';

export const ReadOnlyStepperFieldExample = () => {
return (
<StepperField
label="Stepper"
defaultValue={5}
min={0}
max={10}
step={1}
labelHidden
isReadOnly
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { StepperField } from '@aws-amplify/ui-react';

export const StepperFieldAccessibilityExample = () => {
return (
<StepperField label="Stepper" defaultValue={0} min={0} max={10} step={1} />
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { StepperField } from '@aws-amplify/ui-react';

export const StepperFieldSizeExample = () => {
return (
<>
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
size="small"
labelHidden
/>
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
labelHidden
/>
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
size="large"
labelHidden
/>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { StepperField, useTheme } from '@aws-amplify/ui-react';

export const StepperFieldStylePropsExample = () => {
const { tokens } = useTheme();
return (
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
backgroundColor={tokens.colors.teal[60]}
border={`1px solid ${tokens.colors.teal[60]}`}
color={tokens.colors.white}
labelHidden
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { StepperField } from '@aws-amplify/ui-react';

export const StepperFieldValidationErrorExample = () => {
return (
<StepperField
label="Stepper"
defaultValue={0}
min={0}
max={10}
step={1}
errorMessage="The is an error message."
hasError
labelHidden
/>
);
};
8 changes: 8 additions & 0 deletions docs/src/pages/components/stepperfield/examples/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { ControlledStepperFieldExample } from './ControlledStepperFieldExample';
export { DefaultStepperFieldExample } from './DefaultStepperFieldExample';
export { DisabledStepperFieldExample } from './DisabledStepperFieldExample';
export { ReadOnlyStepperFieldExample } from './ReadOnlyStepperFieldExample';
export { StepperFieldAccessibilityExample } from './StepperFieldAccessibilityExample';
export { StepperFieldSizeExample } from './StepperFieldSizeExample';
export { StepperFieldStylePropsExample } from './StepperFieldStylePropsExample';
export { StepperFieldValidationErrorExample } from './StepperFieldValidationErrorExample';
1 change: 1 addition & 0 deletions docs/src/pages/components/stepperfield/index.page.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: StepperField
description: A StepperField is a number input with buttons to increase or decrease the value.
isPrimitive: true
---

Expand Down
Loading

0 comments on commit 15d28c3

Please sign in to comment.