-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: nested list styling for v5 (#1438)
Co-authored-by: Eric Garcia <eng618@garciaericn.com>
- Loading branch information
1 parent
b8d4961
commit 37fb939
Showing
6 changed files
with
100 additions
and
140 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
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
25 changes: 17 additions & 8 deletions
25
packages/gatsby-theme-carbon/src/components/markdown/Li.js
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,11 +1,20 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { listItem } from './Markdown.module.scss'; | ||
import { ListItem } from '@carbon/react'; | ||
|
||
const Li = ({ children, className, ...rest }) => ( | ||
<li className={cx(className, `cds--list__item`, listItem)} {...rest}> | ||
{children} | ||
</li> | ||
); | ||
const { Provider, Consumer: LiConsumer } = React.createContext({ | ||
hasListItemParent: false, | ||
}); | ||
|
||
export default Li; | ||
const Li = ({ children, ...rest }) => | ||
React.createElement( | ||
ListItem, | ||
{ ...rest }, | ||
React.createElement( | ||
Provider, | ||
{ value: { hasListItemParent: true } }, | ||
children | ||
) | ||
); | ||
|
||
// eslint-disable-next-line no-restricted-exports | ||
export { Li as default, LiConsumer }; |
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
40 changes: 28 additions & 12 deletions
40
packages/gatsby-theme-carbon/src/components/markdown/Ol.js
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,17 +1,33 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { list } from './Markdown.module.scss'; | ||
import { OrderedList } from '@carbon/react'; | ||
import { LiConsumer } from './Li.js'; | ||
import { ordered } from './Markdown.module.scss'; | ||
|
||
const Ol = ({ children, nested, start, className, ...rest }) => { | ||
const classNames = cx(className, `cds--list--ordered--native`, list, { | ||
[`cds--list--nested`]: nested, | ||
const Ol = ({ children, className, ...rest }) => | ||
React.createElement(LiConsumer, null, (value) => { | ||
if (value.hasListItemParent) { | ||
return React.createElement( | ||
OrderedList, | ||
{ | ||
isExpressive: true, | ||
nested: true, | ||
native: true, | ||
...rest, | ||
}, | ||
children | ||
); | ||
} | ||
return React.createElement( | ||
OrderedList, | ||
{ | ||
isExpressive: true, | ||
nested: false, | ||
native: true, | ||
className: ordered, | ||
...rest, | ||
}, | ||
children | ||
); | ||
}); | ||
|
||
return ( | ||
<ol className={classNames} {...rest} start={`${start}`}> | ||
{children} | ||
</ol> | ||
); | ||
}; | ||
|
||
export default Ol; |
37 changes: 26 additions & 11 deletions
37
packages/gatsby-theme-carbon/src/components/markdown/Ul.js
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,16 +1,31 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { list } from './Markdown.module.scss'; | ||
import { UnorderedList } from '@carbon/react'; | ||
import { LiConsumer } from './Li.js'; | ||
import { unordered } from './Markdown.module.scss'; | ||
|
||
const Ul = ({ children, nested, className, ...rest }) => { | ||
const classNames = cx(className, `cds--list--unordered`, list, { | ||
[`cds--list--nested`]: nested, | ||
const Ul = ({ children, className, ...rest }) => | ||
React.createElement(LiConsumer, null, (value) => { | ||
if (value.hasListItemParent) { | ||
return React.createElement( | ||
UnorderedList, | ||
{ | ||
isExpressive: true, | ||
nested: true, | ||
...rest, | ||
}, | ||
children | ||
); | ||
} | ||
return React.createElement( | ||
UnorderedList, | ||
{ | ||
isExpressive: true, | ||
nested: false, | ||
className: unordered, | ||
...rest, | ||
}, | ||
children | ||
); | ||
}); | ||
return ( | ||
<ul className={classNames} {...rest}> | ||
{children} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default Ul; |