Basic discussions forum framework

Adds the basic structure for the Discussions MFE around which future development
will happen.
This commit is contained in:
Kshitij Sobti
2020-08-18 16:58:48 +05:30
parent 56d68e76ad
commit 491f7b7acd
58 changed files with 9313 additions and 4194 deletions

1
src/components/index.js Normal file
View File

@@ -0,0 +1 @@
export * from './selectable-dropdown';

View File

@@ -0,0 +1,55 @@
import { Dropdown } from '@edx/paragon';
import PropTypes from 'prop-types';
import React, { useState } from 'react';
function SelectableDropdown({
options, defaultOption, onChange, label,
}) {
const [selected, setSelected] = useState(options.find(option => (option.value === defaultOption)));
return (
<Dropdown>
<Dropdown.Toggle>
{ label || selected.label }
</Dropdown.Toggle>
<Dropdown.Menu>
{ options
.map(option => (
<Dropdown.Item
type="button"
key={option.value}
onClick={
() => {
setSelected(option);
if (onChange) {
onChange(option);
}
}
}
>
{ option.label }
</Dropdown.Item>
)) }
</Dropdown.Menu>
</Dropdown>
);
}
SelectableDropdown.propTypes = {
options: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.string,
label: PropTypes.string,
}),
).isRequired,
defaultOption: PropTypes.string.isRequired,
onChange: PropTypes.func,
label: PropTypes.node,
};
SelectableDropdown.defaultProps = {
onChange: null,
label: null,
};
export default SelectableDropdown;

View File

@@ -0,0 +1,2 @@
/* eslint-disable import/prefer-default-export */
export { default as SelectableDropdown } from './SelectableDropdown';