-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): covert Fieldset to FC and remove static members (#319)
BREAKING CHANGE: `Form.Fieldset` renamed to `Fieldset` and will now have to `import { Fieldset } from '@bigcommerce/big-design';`
- Loading branch information
1 parent
a525e59
commit f75bd49
Showing
24 changed files
with
271 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/big-design/src/components/Fieldset/Description/Description.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React, { memo } from 'react'; | ||
|
||
import { Small, TextProps } from '../../Typography'; | ||
|
||
export const FieldsetDescription: React.FC<TextProps> = memo(({ className, style, ...props }) => <Small {...props} />); |
1 change: 1 addition & 0 deletions
1
packages/big-design/src/components/Fieldset/Description/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FieldsetDescription } from './Description'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { memo, useMemo } from 'react'; | ||
|
||
import { warning } from '../../utils/warning'; | ||
|
||
import { StyledFieldset } from './styled'; | ||
import { FieldsetDescription } from './Description'; | ||
import { FieldsetLegend } from './Legend'; | ||
|
||
export interface FieldsetProps extends React.FieldsetHTMLAttributes<HTMLFieldSetElement> { | ||
legend?: React.ReactChild; | ||
description?: React.ReactChild; | ||
} | ||
|
||
export const Fieldset: React.FC<FieldsetProps> = memo( | ||
({ className, legend, description, children, style, ...props }) => { | ||
const renderedLegend = useMemo(() => { | ||
if (typeof legend === 'string') { | ||
return <FieldsetLegend>{legend}</FieldsetLegend>; | ||
} | ||
|
||
if (React.isValidElement(legend) && legend.type === FieldsetLegend) { | ||
return legend; | ||
} | ||
|
||
if (!legend) { | ||
return null; | ||
} | ||
|
||
warning('legend must be either a string or a FieldsetLegend component.'); | ||
}, [legend]); | ||
|
||
const renderedDescription = useMemo(() => { | ||
if (typeof description === 'string') { | ||
return <FieldsetDescription>{description}</FieldsetDescription>; | ||
} | ||
|
||
if (React.isValidElement(description) && description.type === FieldsetDescription) { | ||
return description; | ||
} | ||
|
||
if (!description) { | ||
return null; | ||
} | ||
|
||
warning('description must be either a string or a FieldsetDescription component.'); | ||
}, [description]); | ||
|
||
return ( | ||
<StyledFieldset {...props}> | ||
{renderedLegend} | ||
{renderedDescription} | ||
{children} | ||
</StyledFieldset> | ||
); | ||
}, | ||
); |
9 changes: 9 additions & 0 deletions
9
packages/big-design/src/components/Fieldset/Legend/Legend.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React, { memo } from 'react'; | ||
|
||
import { HeadingProps } from '../../Typography'; | ||
|
||
import { StyledFieldsetLegend } from './styled'; | ||
|
||
export const FieldsetLegend: React.FC<HeadingProps> = memo(({ className, style, ...props }) => ( | ||
<StyledFieldsetLegend {...props} /> | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FieldsetLegend } from './Legend'; |
12 changes: 12 additions & 0 deletions
12
packages/big-design/src/components/Fieldset/Legend/styled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { theme as defaultTheme } from '@bigcommerce/big-design-theme'; | ||
import styled, { DefaultTheme, StyledComponent } from 'styled-components'; | ||
|
||
import { StyleableH3 } from '../../Typography/private'; | ||
|
||
export const StyledFieldsetLegend = styled(StyleableH3).attrs({ as: 'legend' })` | ||
&:not(:last-child) { | ||
margin-bottom: ${({ theme }) => theme.spacing.xxSmall}; | ||
} | ||
` as StyledComponent<'legend', DefaultTheme>; | ||
|
||
StyledFieldsetLegend.defaultProps = { theme: defaultTheme }; |
2 changes: 2 additions & 0 deletions
2
...ign/src/components/Form/Fieldset/index.ts → ...g-design/src/components/Fieldset/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { FieldsetProps as _FieldsetProps } from './Fieldset'; | ||
|
||
export { FieldsetDescription } from './Description'; | ||
export { Fieldset } from './Fieldset'; | ||
export { FieldsetLegend } from './Legend'; | ||
export type FieldsetProps = _FieldsetProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { theme as defaultTheme } from '@bigcommerce/big-design-theme'; | ||
import styled from 'styled-components'; | ||
|
||
export const StyledFieldset = styled.fieldset` | ||
border: none; | ||
margin: 0 0 ${({ theme }) => theme.spacing.xLarge}; | ||
padding: 0; | ||
&:last-child { | ||
margin: 0; | ||
} | ||
`; | ||
|
||
StyledFieldset.defaultProps = { theme: defaultTheme }; |
53 changes: 0 additions & 53 deletions
53
packages/big-design/src/components/Form/Fieldset/Fieldset.tsx
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
packages/big-design/src/components/Form/Fieldset/styled.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.