diff --git a/src/components/checkbox/checkbox.tsx b/src/components/checkbox/checkbox.tsx new file mode 100644 index 000000000..c42099cd8 --- /dev/null +++ b/src/components/checkbox/checkbox.tsx @@ -0,0 +1,43 @@ +import './style.scss'; +import * as React from 'react'; +import { ComponentProps } from 'react'; +import { prefixClaName, classNames, getBEMElement } from 'mo/common/className'; + +export interface ICheckbox extends ComponentProps { + id: string; + value?: string; + children?: ReactNode; + onChange?(e: React.ChangeEvent, options?: ICheckbox): void; +} + +export const checkboxClassName = prefixClaName('checkbox'); +const checkboxLabelClassName = getBEMElement(checkboxClassName, 'label'); +const checkboxInputClassName = getBEMElement(checkboxClassName, 'input'); + +export function Checkbox(props: ICheckbox) { + const { className, id, children, value, onChange, ...custom } = props; + + const claNames = classNames(checkboxClassName, className); + + const handleCheckboxChange = (e: React.ChangeEvent) => { + onChange?.(e, { id, value: e.target.value }); + }; + + return ( +
+ + +
+ ); +} diff --git a/src/components/checkbox/index.tsx b/src/components/checkbox/index.tsx new file mode 100644 index 000000000..8d78b3e23 --- /dev/null +++ b/src/components/checkbox/index.tsx @@ -0,0 +1 @@ +export * from './checkbox'; diff --git a/src/components/checkbox/style.scss b/src/components/checkbox/style.scss new file mode 100644 index 000000000..f5e074ef2 --- /dev/null +++ b/src/components/checkbox/style.scss @@ -0,0 +1,44 @@ +@import 'mo/style/common'; +$checkbox: prefix('checkbox'); + +#{$checkbox} { + user-select: none; + + &__input { + height: 0; + visibility: hidden; + width: 0; + + &[type='checkbox']:checked + label::before { + content: '\eab2'; + } + } + + &__label { + cursor: pointer; + outline: none; + padding-left: 26px; + position: relative; + + &::before { + border: 1px solid transparent; + border-radius: 3px; + box-sizing: border-box; + content: ' '; + display: inline-block; + font: normal normal normal 16px/1 codicon; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + height: 18px; + left: 0; + outline: 1px solid transparent; + position: absolute; + text-align: center; + text-decoration: none; + text-rendering: auto; + top: 0; + user-select: none; + width: 18px; + } + } +} diff --git a/src/style/common.scss b/src/style/common.scss index 7934b23e8..0a5a4f254 100644 --- a/src/style/common.scss +++ b/src/style/common.scss @@ -18,6 +18,7 @@ $prefix: 'mo'; .#{$prefix} { bottom: 0; + box-sizing: border-box; font-size: 13px; height: 100%; left: 0; diff --git a/src/style/theme.scss b/src/style/theme.scss index 6fcfe75b8..54f66fac1 100644 --- a/src/style/theme.scss +++ b/src/style/theme.scss @@ -25,6 +25,7 @@ @import 'mo/components/button/style'; @import 'mo/components/input/style'; @import 'mo/components/select/style'; +@import 'mo/components/checkbox/style'; // =============== Workbench =============== // #{prefix($workbench)} { @@ -251,3 +252,20 @@ border-top-color: rgba(255, 255, 255, 0.4); } } + +// =============== Checkbox =============== // + +#{$checkbox} { + &--focus + label::before { + outline-color: rgba(14, 99, 156, 0.8); + } + + &__label { + color: #f0f0f0; + + &::before { + background-color: #3c3c3c; + border-color: #3c3c3c; + } + } +} diff --git a/stories/components/16-Checkbox.stories.tsx b/stories/components/16-Checkbox.stories.tsx new file mode 100644 index 000000000..f4dd44dc0 --- /dev/null +++ b/stories/components/16-Checkbox.stories.tsx @@ -0,0 +1,116 @@ +import * as React from 'react'; +import { storiesOf } from '@storybook/react'; +import { withKnobs } from '@storybook/addon-knobs'; +import { propsTable } from '../common/propsTable'; +import { Checkbox } from 'mo/components/checkbox'; + +const stories = storiesOf('Checkbox', module); +stories.addDecorator(withKnobs); + +const propDefinitions = [ + { + property: 'render', + propType: '() => React.ReactNode', + required: false, + description: 'Default render content', + defaultValue: null, + }, +]; + +stories.add( + 'Basic Usage', + () => { + const onSelectOption = (e, option) => { + console.log('onSelectOption', e, option); + }; + return ( +
+

简述

+

Checkbox component.

+ +

使用示例 1

+
+ + Controls whether and how files path are shown in the + breadcrumbs view. + +
+
+ + Render breadcrumb items with icons. + +
+
+ ); + }, + { + info: { + inline: true, + TableComponent: () => propsTable({ propDefinitions }), + // propTablesExclude: [], + text: ` + 代码示例: + ~~~js + import { useContextView } from 'mo/components/contextview'; + + const contextView = useContextView(); + + const mouseMove = (event: React.MouseEvent): void => { + contextView.show({ + x: event.clientX, + y: event.clientY, + }, () => { + return ( +

Hello World

+ ); + }); + }; + + return ( +
+
+ Hover me! +
+
+ ); + ~~ + `, + }, + } +);