diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29dc190b5b..e17033c190 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `Indicator` component and used it in `MenuItem` and `AccordionTitle` @mnajdova ([#721](https://github.com/stardust-ui/react/pull/721))
- Expose `renderItem` and `renderSelectedItem` callbacks API for `Dropdown` @layershifter ([#746](https://github.com/stardust-ui/react/pull/746))
+### Documentation
+- Refine Shorthand docs page content @kuzhelov ([#751](https://github.com/stardust-ui/react/pull/751))
+
## [v0.17.0](https://github.com/stardust-ui/react/tree/v0.17.0) (2019-01-17)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.16.2...v0.17.0)
diff --git a/docs/src/components/CodeSnippet.tsx b/docs/src/components/CodeSnippet.tsx
index 8231eed77d..f58678f11c 100644
--- a/docs/src/components/CodeSnippet.tsx
+++ b/docs/src/components/CodeSnippet.tsx
@@ -7,10 +7,14 @@ export interface CodeSnippetProps {
fitted?: boolean
label?: string
mode?: 'jsx' | 'html' | 'sh'
- value: string
+ value: string | string[]
style?: React.CSSProperties
}
+const joinToString = (stringOrArray: string | string[]) => {
+ return typeof stringOrArray === 'string' ? stringOrArray : stringOrArray.join('\n')
+}
+
const formatters = {
sh: (val: string = ''): string => val.replace(/^/g, '$ '),
html: (val: string = ''): string => formatCode(val, 'html'),
@@ -19,7 +23,7 @@ const formatters = {
const CodeSnippet = ({ fitted, label, value, mode = 'jsx', ...restProps }: CodeSnippetProps) => {
const format = formatters[mode]
- const formattedValue = format(value)
+ const formattedValue = format(joinToString(value))
// remove eof line break, they are not helpful for snippets
.replace(/\n$/, '')
diff --git a/docs/src/views/ShorthandProps.tsx b/docs/src/views/ShorthandProps.tsx
index af300df509..469bb5a2dd 100644
--- a/docs/src/views/ShorthandProps.tsx
+++ b/docs/src/views/ShorthandProps.tsx
@@ -1,42 +1,251 @@
import * as React from 'react'
import { NavLink } from 'react-router-dom'
+import { Header } from 'semantic-ui-react'
import DocPage from '../components/DocPage/DocPage'
import CodeSnippet from '../components/CodeSnippet'
import Button from '../../../src/components/Button/Button'
-class ShorthandProps extends React.Component {
- render() {
- return (
-
-
- Most components support two APIs: shorthand and children. With
- the shorthand definition we are adding some props to the component in order
- to define it’s content and behavior.
-
-
- When defining the icon and text content displayed in the Button component, we can pass the
- icon and content props.
-
- '} />
-
-
- With the children API, you are responsible for constructing the proper
- markup. You are also responsible for managing the component's state, styling, and
- accessibility. Due to this, you should strive to use the shorthand API wherever possible.
- It is best to leave the details to the component to solve for you.
-
+ It is quite common for Stardust component to have "slots" which accept shorthand values. For
+ example, {code('Button')} component has an {code('icon')} slot which value defines the icon
+ that will be rendered.
+
+
+ {codeExample(``)}
+
+
+ There are several forms of shorthand values that can be provided, but all of them share one
+ common thing - each is eventually evaluated to React Element. Thus, you can think of shorthand
+ values as a recipe to customize rendered React Element at corresponding slot.
+
+
+ {/* SHORTHAND AS AN OBJECT */}
+ {header('Shorthand value as Object')}
+
+ Each component's slot has associated default element type. For example, by default there is{' '}
+ {code('')} element rendered for {code('Button')}'s {code('icon')} slot. It is possible
+ to customize props of this default element by providing props object as shorthand value:
+
+
+ {codeExample([
+ `// 'name' and 'size' will be used as element's props`,
+ ``,
+ ])}
+
+ {/* SHORTHAND AS A PRIMITIVE VALUE */}
+ {header('Shorthand value as Primitive')}
+
+ There is even shorter way to define default element's props - by using a primitive value. In
+ that case provided shorthand value will be taken as a value for 'default prop' of this
+ element.
+
+
+
+ This could be much easier seen with an example. Here, again, we have a {code('Button')}{' '}
+ element with its icon being defined with shorthand - where provided {code('string')} value
+ will be used as icon's {code('name')}:
+
+
+ {codeExample([
+ `<>`,
+ ` `,
+ ``,
+ ` {/* has identical effect to the previous one */}`,
+ ` `,
+ `>`,
+ ])}
+
+ This works because {code('name')} is the default prop of slot's {code('')} element.
+
+
+ {subheader(`Disable slot's rendering`)}
+
+ It is also possible to pass falsy values ({code('false')}, {code('null')} or{' '}
+ {code('undefined')}) to shorthand prop - in that case there will be nothing rendered for the
+ component's slot.
+
+
+ {/* SHORTHAND AS REACT ELEMENT */}
+ {header('Shorthand value as React Element')}
+
+ There are cases where it might be necessary to customize element tree that will be rendered as
+ a slot's value. Returning to {code('Button')} example, we might want to render {code('')}{' '}
+ instead of default {code('')} element. In that case necessary element might be
+ directly provided as shorthand value:
+