- Selected members:
+ Selected members:
- {Object.entries(selected).map(([ groupId, values ], idx) => {
+ {Object.entries(selected).map(([groupId, values], idx) => {
return values.length > 0 ? (
{groupId}: {values.join(', ')}
@@ -868,111 +1505,228 @@ class SelectMembersExample extends React.Component {
)
}
-}
-
-const pages = [
- {
- id: 'root',
- subPages: [
- { id: 'courses', label: 'Courses' },
- { id: 'groups', label: 'Groups' },
- { id: 'consortiums', label: 'Consortiums' }
- ]
- },
- {
- id: 'courses',
- groups: [
- {
- id: 'course1',
- label: 'Course 1',
- selectableType: 'multiple',
- members: [
- { id: 'course1_1', name: 'Hanna Septimus' },
- { id: 'course1_2', name: 'Kadin Press' },
- { id: 'course1_3', name: 'Kaiya Botosh' },
- ]
- },
- {
- id: 'course2',
- label: 'Course 2',
- selectableType: 'multiple',
- members: [
- { id: 'course2_1', name: 'Leo Calzoni' },
- { id: 'course2_2', name: 'Gretchen Gouse' },
- ]
- }
- ]
- },
- {
- id: 'groups',
- groups: [
- {
- id: 'group1',
- label: 'Group 1',
- selectableType: 'multiple',
- members: [
- { id: 'groups1_1', name: 'Penka Okabe' },
- { id: 'groups1_2', name: 'Ausma Meggyesfalvi' },
- { id: 'groups1_3', name: 'Endrit Höfler' },
- { id: 'groups1_4', name: 'Ryuu Carey' },
- { id: 'groups1_5', name: 'Daphne Dioli' },
- ]
- }
- ]
- },
- {
- id: 'consortiums',
- groups: [
- {
- id: 'consortium1',
- label: 'Consortium 1',
- selectableType: 'multiple',
- members: [
- { id: 'consortium1_1', name: 'Brahim Gustavsson' },
- { id: 'consortium1_2', name: 'Elodia Dreschner' },
- ]
- },
- {
- id: 'consortium2',
- label: 'Consortium 2',
- selectableType: 'multiple',
- members: [
- { id: 'consortium2_1', name: 'Darwin Peter' },
- { id: 'consortium2_2', name: 'Sukhrab Burnham' },
- ]
- },
- {
- id: 'consortium3',
- label: 'Consortium 3',
- selectableType: 'multiple',
- members: [
- { id: 'consortium3_1', name: 'Jeffry Antonise' },
- { id: 'consortium3_2', name: 'Bia Regenbogen' },
- ]
- }
- ]
- }
-]
-render()
-```
+ const pages = [
+ {
+ id: 'root',
+ subPages: [
+ { id: 'courses', label: 'Courses' },
+ { id: 'groups', label: 'Groups' },
+ { id: 'consortiums', label: 'Consortiums' }
+ ]
+ },
+ {
+ id: 'courses',
+ groups: [
+ {
+ id: 'course1',
+ label: 'Course 1',
+ selectableType: 'multiple',
+ members: [
+ { id: 'course1_1', name: 'Hanna Septimus' },
+ { id: 'course1_2', name: 'Kadin Press' },
+ { id: 'course1_3', name: 'Kaiya Botosh' }
+ ]
+ },
+ {
+ id: 'course2',
+ label: 'Course 2',
+ selectableType: 'multiple',
+ members: [
+ { id: 'course2_1', name: 'Leo Calzoni' },
+ { id: 'course2_2', name: 'Gretchen Gouse' }
+ ]
+ }
+ ]
+ },
+ {
+ id: 'groups',
+ groups: [
+ {
+ id: 'group1',
+ label: 'Group 1',
+ selectableType: 'multiple',
+ members: [
+ { id: 'groups1_1', name: 'Penka Okabe' },
+ { id: 'groups1_2', name: 'Ausma Meggyesfalvi' },
+ { id: 'groups1_3', name: 'Endrit Höfler' },
+ { id: 'groups1_4', name: 'Ryuu Carey' },
+ { id: 'groups1_5', name: 'Daphne Dioli' }
+ ]
+ }
+ ]
+ },
+ {
+ id: 'consortiums',
+ groups: [
+ {
+ id: 'consortium1',
+ label: 'Consortium 1',
+ selectableType: 'multiple',
+ members: [
+ { id: 'consortium1_1', name: 'Brahim Gustavsson' },
+ { id: 'consortium1_2', name: 'Elodia Dreschner' }
+ ]
+ },
+ {
+ id: 'consortium2',
+ label: 'Consortium 2',
+ selectableType: 'multiple',
+ members: [
+ { id: 'consortium2_1', name: 'Darwin Peter' },
+ { id: 'consortium2_2', name: 'Sukhrab Burnham' }
+ ]
+ },
+ {
+ id: 'consortium3',
+ label: 'Consortium 3',
+ selectableType: 'multiple',
+ members: [
+ { id: 'consortium3_1', name: 'Jeffry Antonise' },
+ { id: 'consortium3_2', name: 'Bia Regenbogen' }
+ ]
+ }
+ ]
+ }
+ ]
+
+ render()
+ ```
### Disabled prop
You can disable the whole Drilldown or its sub-components with the `disabled` prop. The only option that can not be disabled is the Back navigation.
-```js
----
-type: example
----
-class DisabledExample extends React.Component {
- state = {
- disabled: 'None',
- withTrigger: false
+- ```js
+ class DisabledExample extends React.Component {
+ state = {
+ disabled: 'None',
+ withTrigger: false
+ }
+
+ render() {
+ const { disabled, withTrigger } = this.state
+
+ const disabledDrilldown = disabled === 'Drilldown'
+ const disabledPages = disabled === 'Pages'
+ const disabledGroups = disabled === 'Groups'
+ const disabledOptions = disabled === 'Options'
+
+ return (
+
+
+
+ Toggle button}
+ disabled={disabledDrilldown}
+ >
+
+
+ Option with subPage navigation
+
+
+ Option
+
+
+ {['Apple', 'Orange', 'Banana', 'Strawberry'].map((item) => (
+
+ {item}
+
+ ))}
+
+
+
+
+ {['Option 1', 'Option 2', 'Option 3', 'Option 4'].map(
+ (item) => (
+
+ {item}
+
+ )
+ )}
+
+
+
+
+
+
+ Settings}
+ colSpacing="medium"
+ layout="columns"
+ vAlign="top"
+ >
+ {
+ this.setState({ disabled: value })
+ }}
+ defaultValue="None"
+ name="disabledPart"
+ description="Select disabled"
+ >
+ {['None', 'Drilldown', 'Pages', 'Groups', 'Options'].map(
+ (part) => (
+
+ )
+ )}
+
+
+ {
+ this.setState({ withTrigger: !this.state.withTrigger })
+ }}
+ />
+
+
+
+ )
+ }
}
- render() {
- const { disabled, withTrigger } = this.state
+ render()
+ ```
+
+- ```js
+ const DisabledExample = () => {
+ const [disabled, setDisabled] = useState('None')
+ const [withTrigger, setWithTrigger] = useState(false)
const disabledDrilldown = disabled === 'Drilldown'
const disabledPages = disabled === 'Pages'
@@ -980,11 +1734,11 @@ class DisabledExample extends React.Component {
const disabledOptions = disabled === 'Options'
return (
-
-
-
+
+
+
Toggle button}
@@ -998,33 +1752,34 @@ class DisabledExample extends React.Component {
>
Option with subPage navigation
-
+
Option
- {['Apple', 'Orange', 'Banana', 'Strawberry'].map(
- item => (
-
- {item}
-
- )
- )}
+ {['Apple', 'Orange', 'Banana', 'Strawberry'].map((item) => (
+
+ {item}
+
+ ))}
@@ -1034,7 +1789,7 @@ class DisabledExample extends React.Component {
disabled={disabledPages}
>
{['Option 1', 'Option 2', 'Option 3', 'Option 4'].map(
- item => (
+ (item) => (
{
- this.setState({ disabled: value })
+ setDisabled(value)
}}
defaultValue="None"
name="disabledPart"
description="Select disabled"
>
- {['None', 'Drilldown', 'Pages', 'Groups', 'Options'].map(part => )}
+ {['None', 'Drilldown', 'Pages', 'Groups', 'Options'].map(
+ (part) => (
+
+ )
+ )}
{
- this.setState({ withTrigger: !this.state.withTrigger })
- }
- }
+ onChange={() => {
+ setWithTrigger(!withTrigger)
+ }}
/>
)
}
-}
-render()
-```
+ render()
+ ```
### shouldHideOnSelect
@@ -1232,179 +1988,400 @@ type: example
The following example showcases an editable drilldown that can add or delete options.
-```js
----
-type: example
----
+- ```js
+ class EditableStructureExample extends React.Component {
+ constructor(props) {
+ super(props)
+
+ this.state = {
+ districtsData: {
+ d1: {
+ label: 'District 1',
+ schools: ['s1']
+ }
+ },
+ schoolsData: {
+ s1: {
+ label: 'School 1',
+ districtId: 'd1',
+ isSelected: false
+ }
+ }
+ }
-class EditableStructureExample extends React.Component {
- constructor(props) {
- super(props)
+ this.districtCounter = Object.keys(this.state.districtsData).length
+ this.schoolCounter = Object.keys(this.state.schoolsData).length
+ }
- this.state = {
- districtsData: {
- d1: {
- label: 'District 1',
- schools: ['s1']
+ toggleSelectedSchool(id, school) {
+ this.setState({
+ schoolsData: {
+ ...this.state.schoolsData,
+ [id]: { ...school, isSelected: !school.isSelected }
}
- },
- schoolsData: {
- s1: {
- label: 'School 1',
- districtId: 'd1',
- isSelected: false
+ })
+ }
+
+ renderSelectedIcon(isSelected) {
+ return
+ }
+
+ renderAddAction(label) {
+ return (
+
+
+
+ New {label}
+
+
+ )
+ }
+
+ addDistrict() {
+ const { districtsData } = this.state
+ this.districtCounter++
+ const districtNumber = this.districtCounter
+ const districtId = `d${districtNumber}`
+
+ this.setState({
+ districtsData: {
+ ...districtsData,
+ [districtId]: {
+ label: `District ${districtNumber}`,
+ schools: []
+ }
}
- }
+ })
}
- this.districtCounter = Object.keys(this.state.districtsData).length
- this.schoolCounter = Object.keys(this.state.schoolsData).length
- }
+ addSchool(districtId) {
+ const { districtsData, schoolsData } = this.state
+ const district = districtsData[districtId]
- toggleSelectedSchool(id, school) {
- this.setState({ schoolsData: {
- ...this.state.schoolsData,
- [id]: { ...school, isSelected: !school.isSelected }
- } })
- }
+ this.schoolCounter++
+ const schoolNumber = this.schoolCounter
+ const schoolId = `s${schoolNumber}`
- renderSelectedIcon(isSelected) {
- return (
-
- )
+ this.setState({
+ districtsData: {
+ ...districtsData,
+ [districtId]: {
+ ...district,
+ schools: [...district.schools, schoolId]
+ }
+ },
+ schoolsData: {
+ ...schoolsData,
+ [schoolId]: {
+ label: `School ${schoolNumber}`,
+ districtId,
+ isSelected: false
+ }
+ }
+ })
+ }
+
+ renderDeleteOption(type, label, idToDelete) {
+ const id = type === 'school' ? 'deleteSchool' : 'deleteDistrict'
+ const callback =
+ type === 'school' ? this.deleteSchool : this.deleteDistrict
+ const separatorId = `${idToDelete}__separator`
+
+ return [
+ ,
+ {
+ callback(idToDelete)
+ }}
+ themeOverride={(_componentTheme, currentTheme) => {
+ return { color: currentTheme.colors.textDanger }
+ }}
+ >
+
+
+ Delete {label}
+
+
+ ]
+ }
+
+ deleteSchool = (id) => {
+ const { districtsData, schoolsData } = this.state
+ const { [id]: school, ...restSchools } = schoolsData
+ const { districtId } = school
+ const district = districtsData[districtId]
+
+ this.setState({
+ schoolsData: restSchools,
+ districtsData: {
+ ...districtsData,
+ [districtId]: {
+ ...district,
+ schools: district.schools.filter((schoolId) => schoolId !== id)
+ }
+ }
+ })
+ }
+
+ deleteDistrict = (id) => {
+ const { districtsData, schoolsData } = this.state
+ const { [id]: district, ...restDistricts } = districtsData
+
+ const filteredSchools = {}
+
+ Object.entries(schoolsData).forEach(([schoolId, school]) => {
+ if (school.districtId !== id) {
+ filteredSchools[schoolId] = school
+ }
+ })
+
+ this.setState({
+ districtsData: restDistricts,
+ schoolsData: filteredSchools
+ })
+ }
+
+ render() {
+ const { districtsData, schoolsData } = this.state
+ const districts = Object.entries(districtsData)
+ const schools = Object.entries(schoolsData)
+
+ return (
+
+ {
+ this.addDistrict()
+ }}
+ >
+ {districts.map(([id, district]) => {
+ const { label } = district
+ return (
+
+ {label}
+
+ )
+ })}
+
+
+ {districts.map(([districtId, district]) => {
+ const { label, schools } = district
+ return (
+ {
+ this.addSchool(districtId)
+ }}
+ >
+ {schools.map((id) => {
+ const { label, isSelected } = this.state.schoolsData[id]
+ return (
+
+ {label}
+
+ )
+ })}
+ {this.renderDeleteOption('district', label, districtId)}
+
+ )
+ })}
+
+ {schools.map(([id, school]) => {
+ const { label, isSelected } = school
+ return (
+
+ {
+ this.toggleSelectedSchool(id, school)
+ }}
+ >
+ {isSelected ? 'Deselect' : 'Select'} {label}
+
+ {this.renderDeleteOption('school', label, id)}
+
+ )
+ })}
+
+ )
+ }
}
- renderAddAction(label) {
- return (
-
-
- New {label}
-
+ render()
+ ```
+
+- ```js
+ const EditableStructureExample = () => {
+ const [districtsData, setDistrictsData] = useState({
+ d1: {
+ label: 'District 1',
+ schools: ['s1']
+ }
+ })
+ const [schoolsData, setSchoolsData] = useState({
+ s1: {
+ label: 'School 1',
+ districtId: 'd1',
+ isSelected: false
+ }
+ })
+
+ const [districtCounter, setDistrictCounter] = useState(
+ Object.keys(districtsData).length
)
- }
+ const [schoolCounter, setSchoolCounter] = useState(
+ Object.keys(schoolsData).length
+ )
+
+ const districts = Object.entries(districtsData)
+ const schools = Object.entries(schoolsData)
+
+ const toggleSelectedSchool = (id, school) => {
+ setSchoolsData({
+ ...schoolsData,
+ [id]: { ...school, isSelected: !school.isSelected }
+ })
+ }
+
+ const renderSelectedIcon = (isSelected) => {
+ return
+ }
+
+ const renderAddAction = (label) => {
+ return (
+
+
+
+ New {label}
+
+
+ )
+ }
- addDistrict() {
- const { districtsData } = this.state
- this.districtCounter++
- const districtNumber = this.districtCounter
- const districtId = `d${districtNumber}`
+ const addDistrict = () => {
+ const newDistrictCounter = districtCounter + 1
+ const districtNumber = newDistrictCounter
+ const districtId = `d${newDistrictCounter}`
+ setDistrictCounter(newDistrictCounter)
- this.setState({
- districtsData: {
+ setDistrictsData((districtsData) => ({
...districtsData,
[districtId]: {
label: `District ${districtNumber}`,
schools: []
}
- }
- })
- }
-
- addSchool(districtId) {
- const { districtsData, schoolsData } = this.state
- const district = districtsData[districtId]
+ }))
+ }
- this.schoolCounter++
- const schoolNumber = this.schoolCounter
- const schoolId = `s${schoolNumber}`
+ const addSchool = (districtId) => {
+ const newSchoolCounter = schoolCounter + 1
+ const district = districtsData[districtId]
+ const schoolNumber = newSchoolCounter
+ const schoolId = `s${newSchoolCounter}`
+ setSchoolCounter(newSchoolCounter)
- this.setState({
- districtsData: {
+ setDistrictsData((districtsData) => ({
...districtsData,
[districtId]: {
- ...district,
+ ...districtsData[districtId],
schools: [...district.schools, schoolId]
}
- },
- schoolsData: {
+ }))
+
+ setSchoolsData((schoolsData) => ({
...schoolsData,
[schoolId]: {
label: `School ${schoolNumber}`,
districtId,
isSelected: false
}
- }
- })
- }
+ }))
+ }
- renderDeleteOption(type, label, idToDelete) {
- const id = type === 'school' ? "deleteSchool" : "deleteDistrict"
- const callback = type === 'school' ? this.deleteSchool : this.deleteDistrict
- const separatorId = `${idToDelete}__separator`
-
- return [
- ,
- { callback(idToDelete) }}
- themeOverride={(_componentTheme, currentTheme) => {
- return { color: currentTheme.colors.textDanger }
- }}
- >
-
-
- Delete {label}
-
-
- ]
- }
+ const renderDeleteOption = (type, label, idToDelete) => {
+ const id = type === 'school' ? 'deleteSchool' : 'deleteDistrict'
+ const callback = type === 'school' ? deleteSchool : deleteDistrict
+ const separatorId = `${idToDelete}__separator`
+
+ return [
+ ,
+ {
+ callback(idToDelete)
+ }}
+ themeOverride={(_componentTheme, currentTheme) => {
+ return { color: currentTheme.colors.textDanger }
+ }}
+ >
+
+
+ Delete {label}
+
+
+ ]
+ }
- deleteSchool = (id) => {
- const { districtsData, schoolsData } = this.state
- const { [id]: school, ...restSchools } = schoolsData
- const { districtId } = school
- const district = districtsData[districtId]
+ const deleteSchool = (id) => {
+ const { [id]: school, ...restSchools } = schoolsData
+ const { districtId } = school
+ const district = districtsData[districtId]
- this.setState({
- schoolsData: restSchools,
- districtsData: {
+ setSchoolsData(restSchools)
+ setDistrictsData({
...districtsData,
[districtId]: {
...district,
- schools: district.schools.filter(schoolId => schoolId !== id)
+ schools: district.schools.filter((schoolId) => schoolId !== id)
}
- }
- })
- }
-
- deleteDistrict = (id) => {
- const { districtsData, schoolsData } = this.state
- const { [id]: district, ...restDistricts } = districtsData
+ })
+ }
- const filteredSchools = {}
+ const deleteDistrict = (id) => {
+ const { [id]: district, ...restDistricts } = districtsData
- Object.entries(schoolsData).forEach(([schoolId, school]) => {
- if (school.districtId !== id) {
- filteredSchools[schoolId] = school
- }
- })
+ const filteredSchools = {}
- this.setState({
- districtsData: restDistricts,
- schoolsData: filteredSchools
- })
- }
+ Object.entries(schoolsData).forEach(([schoolId, school]) => {
+ if (school.districtId !== id) {
+ filteredSchools[schoolId] = school
+ }
+ })
- render() {
- const { districtsData, schoolsData } = this.state
- const districts = Object.entries(districtsData)
- const schools = Object.entries(schoolsData)
+ setDistrictsData(restDistricts)
+ setSchoolsData(filteredSchools)
+ }
return (
-
+
{
- this.addDistrict()
+ addDistrict()
}}
>
{districts.map(([id, district]) => {
@@ -1421,32 +2398,32 @@ class EditableStructureExample extends React.Component {
})}
- {districts.map(([districtId , district]) => {
+ {districts.map(([districtId, district]) => {
const { label, schools } = district
return (
{
- this.addSchool(districtId)
+ addSchool(districtId)
}}
>
{schools.map((id) => {
- const { label, isSelected } = this.state.schoolsData[id]
+ const { label, isSelected } = schoolsData[id]
return (
{label}
)
})}
- {this.renderDeleteOption('district', label, districtId)}
+ {renderDeleteOption('district', label, districtId)}
)
})}
@@ -1461,24 +2438,23 @@ class EditableStructureExample extends React.Component {
>
{
- this.toggleSelectedSchool(id, school)
+ toggleSelectedSchool(id, school)
}}
>
{isSelected ? 'Deselect' : 'Select'} {label}
- {this.renderDeleteOption('school', label, id)}
+ {renderDeleteOption('school', label, id)}
)
})}
)
}
-}
-render()
-```
+ render()
+ ```
### Guidelines