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

docs(ui-select,ui-selectable): function based examples are added to S… #1708

Open
wants to merge 1 commit 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
152 changes: 101 additions & 51 deletions docs/guides/accessing-the-dom.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,70 +25,120 @@ class MyComponent extends React.Component {
return <div ref={this.ref}>Content</div>
}
}
```

Good Usage Example with `ref`:
```

```js
```javascript
---
type: example
type: code
---
const MyComponent = React.forwardRef((props, ref) => {
return <div ref={ref}>Content</div>
})
```

class GoodComponent extends React.Component {
constructor(props) {
super(props)
this.ref = React.createRef()
Good Usage Example with `ref`:

- ```js
class GoodComponent extends React.Component {
constructor(props) {
super(props)
this.ref = React.createRef()
}
render() {
return <span ref={this.ref}>Good Position target component</span>
}
}
render() {
return (<span ref={this.ref}>Good Position target component</span>)
const Example = () => {
return (
<View as="div" padding={'large'}>
<Position
renderTarget={<GoodComponent />}
placement="end center"
offsetX="20px"
>
<span style={{ padding: '8px', background: 'white' }}>
Positioned content
</span>
</Position>
</View>
)
}
}
render(<Example />)
```

const Example = () => {
return (
<View as="div" padding={'large'}>
<Position
renderTarget={<GoodComponent />}
placement='end center'
offsetX='20px'
>
<span style={{ padding: '8px', background: 'white' }}>Positioned content</span>
</Position>
</View>
)
}
- ```js
const GoodComponent = React.forwardRef((props, ref) => {
return <span ref={ref}>Good Position target component</span>
})

render(<Example />)
```
const Example = () => {
return (
<View as="div" padding={'large'}>
<Position
renderTarget={<GoodComponent />}
placement="end center"
offsetX="20px"
>
<span style={{ padding: '8px', background: 'white' }}>
Positioned content
</span>
</Position>
</View>
)
}
render(<Example />)
```

Bad Usage Example without `ref`, that will result in InstUI calling `ReactDOM.findDOMNode()` and throw warnings:

```js
---
type: example
---
class BadComponent extends React.Component {
constructor(props) {
super(props)
- ```js
class BadComponent extends React.Component {
constructor(props) {
super(props)
}
render() {
return <span>Bad Position target component</span>
}
}
render() {
return (<span>Bad Position target component</span>)

const Example = () => {
return (
<View as="div" padding={'large'}>
<Position
renderTarget={<BadComponent />}
placement="end center"
offsetX="20px"
>
<span style={{ padding: '8px', background: 'white' }}>
Positioned content
</span>
</Position>
</View>
)
}
}
render(<Example />)
```

const Example = () => {
return (
<View as="div" padding={'large'}>
<Position
renderTarget={<BadComponent />}
placement='end center'
offsetX='20px'
>
<span style={{ padding: '8px', background: 'white' }}>Positioned content</span>
</Position>
</View>
)
}
- ```js
const BadComponent = React.forwardRef((props, ref) => {
ToMESSKa marked this conversation as resolved.
Show resolved Hide resolved
return <span>Bad Position target component</span>
})

render(<Example />)
```
const Example = () => {
return (
<View as="div" padding={'large'}>
<Position
renderTarget={<BadComponent />}
placement="end center"
offsetX="20px"
>
<span style={{ padding: '8px', background: 'white' }}>
Positioned content
</span>
</Position>
</View>
)
}
render(<Example />)
```
Loading
Loading