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

Integration with Doc Prop #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- Doc Prop dependency and integration (via markdown placeholder on components readme.md).

## [2.1.2] - 2020-06-24
### Fixed
- Link `Next Article` and `Previous Article` to work with trailing slash.
Expand Down
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
This is the UI for VTEX IO documentation at https://vtex.io/docs.

To contribute to the available content, please refer to [IO Documentation](https://github.com/vtex-apps/io-documentation).

## Doc Prop

For Store Framework components, props can be documented using Doc Prop.
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"vtex.styleguide": "9.x",
"vtex.store-drawer": "0.x",
"vtex.docs-graphql": "1.x",
"vtex.device-detector": "0.x"
"vtex.device-detector": "0.x",
"vtex.doc-prop": "1.x"
},
"mustUpdateAt": "2018-09-05",
"categories": [],
Expand Down
19 changes: 18 additions & 1 deletion react/components/CustomTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { Fragment } from 'react'
import { useRuntime } from 'vtex.render-runtime'
import { useDevice } from 'vtex.device-detector'
import { Link } from 'vtex.styleguide'
import { DocProp } from 'vtex.doc-prop'

import ArticleNav from './ArticleNav'
import { slug } from '../modules'
Expand All @@ -12,6 +13,7 @@ import {
removeIgnoredNodesFromDocs,
} from '../modules/ignoreTokens'
import CodeBlock from './CodeBlock'
import { DOC_PROP_PLACEHOLDER_MATCH, DOC_PROP_PLACEHOLDER } from '../utils/constants'

export const CustomRenderers = {
root: ({ children }: { children: any[] }) => {
Expand Down Expand Up @@ -187,7 +189,9 @@ export const CustomRenderers = {
),
paragraph: (props: any) => {
if (props.children === '' || props.children.length === 0) return null
return <p className="t-body c-on-base mt0 lh-copy mb6">{props.children}</p>

return checkDocProp(props) ?
getDocProp(props) : (<p className="t-body c-on-base mt0 lh-copy mb6">{props.children}</p>)
},
strong: (props: any) => <strong className="fw7">{props.children}</strong>,
table: (props: any) => (
Expand Down Expand Up @@ -225,3 +229,16 @@ function getHeadingSlug(childNodes: any) {
(childNodes[0].props.children && slug(childNodes[0].props.children)) || ''
)
}

function checkDocProp(props: any) {
const paragraphValue = props?.children[0]?.props?.value ?? ''

return paragraphValue.includes(DOC_PROP_PLACEHOLDER)
}

function getDocProp(props: any) {
const match = props.children[0].props.value.match(DOC_PROP_PLACEHOLDER_MATCH)
const blockInterface = match?.[1] ?? ''

return <DocProp blockInterface={blockInterface} />
}
3 changes: 3 additions & 0 deletions react/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DOC_PROP_PLACEHOLDER = '%PROPS='

export const DOC_PROP_PLACEHOLDER_MATCH = /\%PROPS=(.*)\%/