story.jsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React from 'react'
  15. import { storiesOf } from '@storybook/react'
  16. import styled from 'styled-components'
  17. import WizardOptionsField from '.'
  18. const WizardOptionsFieldStyled = styled(WizardOptionsField) `
  19. width: 319px;
  20. justify-content: space-between;
  21. `
  22. class Wrapper extends React.Component {
  23. constructor() {
  24. super()
  25. this.state = { value: null }
  26. }
  27. handleChange(value) {
  28. this.setState({ value })
  29. }
  30. render() {
  31. return (
  32. <div style={{ width: '800px' }}>
  33. <WizardOptionsFieldStyled
  34. {...this.props}
  35. value={this.state.value}
  36. onChange={value => { this.handleChange(value) }}
  37. />
  38. </div>
  39. )
  40. }
  41. }
  42. storiesOf('WizardOptionsField', module)
  43. .add('string', () => (
  44. <Wrapper
  45. name="String input"
  46. type="string"
  47. />
  48. ))
  49. .add('switch with boolean', () => (
  50. <Wrapper
  51. name="Switch"
  52. type="boolean"
  53. />
  54. ))
  55. .add('switch with strict-boolean', () => (
  56. <Wrapper
  57. name="Switch"
  58. type="strict-boolean"
  59. />
  60. ))
  61. .add('enum dropdown', () => (
  62. <Wrapper
  63. type="string"
  64. name="Port Reuse"
  65. enum={['keep_mac', 'reuse_ports', 'replace_mac']}
  66. />
  67. ))
  68. .add('object table', () => (
  69. <Wrapper
  70. type="object"
  71. name="Object table"
  72. properties={[
  73. { type: 'boolean', name: 'prop-1', label: 'Property 1' },
  74. { type: 'boolean', name: 'prop-2', label: 'Property 2' },
  75. ]}
  76. valueCallback={prop => prop.name === 'prop-2'}
  77. />
  78. ))