Skip to content

Commit

Permalink
docs: remove PropertyInEdit from the docs
Browse files Browse the repository at this point in the history
fixes: #599
  • Loading branch information
Wojciech Krysiak authored and Wojciech Krysiak committed Sep 23, 2020
1 parent fd6a3b1 commit 3e8c540
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
51 changes: 1 addition & 50 deletions src/frontend/components/property-type/base-property-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,56 +136,7 @@ export type ShowPropertyProps = {


/**
* On change callback - It takes either
* one argument which is entire {@link RecordJSON} or 2 arguments - one
* __property.name__ and the second one: __value__. Used by the __edit__ and __filter__ components.
*
* Lets take a look at an example of overriding edit component:
* ```typescript
* import React, { ReactNode } from 'react'
* import { BasePropertyProps, PropertyInEdit, StyledInput } from 'admin-bro'
*
* export default class Edit extends React.Component<PropertyProps> {
* constructor(props) {
* super(props)
* this.handleInputChange = this.handleInputChange.bind(this)
* }
*
* handleInputChange(event): void {
* const { onChange, property, record } = this.props
*
* // Here is the interesting part:
* onChange(property.name, event.target.value)
*
* // or you can pass an entire record. This is the same as above but gives you
* // much more flexibility
* const newRecord = { ...record }
* newRecord.params[property.name] = event.target.value
* onChange(newRecord)
* }
*
* render(): ReactNode {
* const { property, record } = this.props
* const error = record.errors && record.errors[property.name]
* const value = (record.params && typeof record.params[property.name] !== 'undefined')
* ? record.params[property.name]
* : ''
* return (
* <PropertyInEdit property={property} error={error}>
* <StyledInput
* type="text"
* className="input"
* id={property.name}
* name={property.name}
* onChange={this.handleInputChange}
* value={value}
* />
* </PropertyInEdit>
* )
* }
* }
* ```
*
* @load ./docs/on-property-change.doc.md
* @memberof BasePropertyComponent
* @alias OnPropertyChange
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
On change callback - It can take:

* one argument which is an entire {@link RecordJSON}
* 2 arguments - one __property.name__ and the second one: __value__.

* Used by the __edit__ and __filter__ components.

Let's take a look at an example of the edit component

It has one button: "Set Name". When this button is clicked - it triggers `onChange` callback
function. In this case we are passing an updated record, so that we can change value of another
property: `name`.

```javascript
import React from 'react'
import { unflatten } from 'admin-bro'
import { Button, Box } from '@admin-bro/design-system'

const ValueTrigger = (props) => {
const { onChange, record } = props

const handleClick = (): void => {
onChange({
...record,
params: {
...record.params,
name: 'my new name',
},
})
}

return (
<Box mb="xxl">
<Button type="button" onClick={handleClick}>Set Name</Button>
</Box>
)
}

export default ValueTrigger

```

0 comments on commit 3e8c540

Please sign in to comment.