Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
caiwuu committed Jul 9, 2024
1 parent 4569278 commit 50c9b82
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
19 changes: 16 additions & 3 deletions packages/editor/toolBar/compinents/DialogContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@ const headerOps = [
[5, "H5"],
[6, "H6"],
]
const fontSizeOps = [10, 11, 12, 14, 16, 18, 20, 24, 36, 48, 60]
function headerClickHandle (e, vm) {
const val = e.target.dataset.headervalue
if (val) {
vm.props.onOk(val)
vm.props.onOk(+val)
}
}
const comMap = {
color: (h, self) => (
<div id="colorPicker">
<ColorPicker onOk={self.props.onOk} color='#666666'></ColorPicker>
<ColorPicker onOk={self.props.onOk} color={self.props.value}></ColorPicker>
</div>
),
background: (h, self) => (
<div id="colorPicker">
<ColorPicker onOk={self.props.onOk} color={self.props.value}></ColorPicker>
</div>
),
header: (h, self) => {
return <div onClick={(e) => headerClickHandle(e, self)} style="color:#666">
{
headerOps.map(ele => h(ele[1], { "data-headervalue": ele[0], style: { margin: '2px 0' }, class: 'header-selector-item' }, [ele[1]]))
headerOps.map(ele => h(ele[1], { "data-headervalue": ele[0], style: { margin: '2px 8px' }, class: `header-selector-item ${self.props.value === ele[0] ? 'active' : ''}` }, [ele[1]]))
}
</div>
},
fontSize: (h, self) => {
return <div onClick={(e) => headerClickHandle(e, self)} style="color:#666">
{
fontSizeOps.map(ele => h('div', { "data-headervalue": ele, style: { margin: '2px 8px' }, class: `header-selector-item ${self.props.value === ele + 'px' ? 'active' : ''}` }, [ele]))
}
</div>
}
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/toolBar/compinents/toolBar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
background rgb(40 40 40)
padding 6px

.header-selector-item:hover{
.header-selector-item:hover,.header-selector-item.active{
background: #ddd;
color: #2ac9f9
}
Expand Down
12 changes: 6 additions & 6 deletions packages/editor/toolBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ export default class ToolBar extends Component {
class ToolBarItem extends Component {
constructor(props) {
super(props)
this.state = { active: false, dialogVisiable: false }
this.state = { currValue: false, dialogVisiable: false }
this.props.toolBarItemInses.push(this)
this.dialogRef = createRef()
this.barItemRef = createRef()
}

onNotice (commonKeyValue) {
if (commonKeyValue[this.props.name] !== this.state.active) {
if (commonKeyValue[this.props.name] !== this.state.currValue) {
this.setState({
active: commonKeyValue[this.props.name],
currValue: commonKeyValue[this.props.name],
})
}
}
getStyleColor () {
if (!this.state.active) return 'rgb(227 227 227);'
if (!this.state.currValue) return 'rgb(227 227 227);'
if (this.props.name === 'color') return 'rgb(227 227 227);'
return 'rgb(42 201 249)'
}
Expand All @@ -80,13 +80,13 @@ class ToolBarItem extends Component {
<use xlink:href={this.props.icon}></use>
</svg>
{
this.props.name === 'color' ? <span class="color-line" style={`background:${this.state.active ? this.state.active : '#000'}`}></span> : ''
this.props.name === 'color' ? <span class="color-line" style={`background:${this.state.currValue ? this.state.currValue : '#000'}`}></span> : ''
}
{
this.props.showDialog && this.state.dialogVisiable
?
<div style='background:#efefef;position:absolute;top:35px;z-index:1'>
<DialogContent onOk={this.onOk} name={this.props.name}></DialogContent>
<DialogContent value={this.state.currValue || '#000'} onOk={this.onOk} name={this.props.name}></DialogContent>
</div>
: ''
}
Expand Down
5 changes: 4 additions & 1 deletion packages/editor/toolBar/toolBarOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ const toolBarOptions = [
icon: '#icon-header',
showDialog: true,
commandHandle: (editor, level) => setComponent(editor, path => {
console.log(path);
path.node.formats = { header: level }
})
},
{
tooltip: '字体大小',
name: 'fontSize',
icon: '#icon-font-size',
showDialog: true,
commandHandle: (editor, fontSize) => setFormat(editor, path => (path.node.formats.fontSize = `${fontSize}px`))
},
{
tooltip: '字体颜色',
Expand Down Expand Up @@ -60,6 +61,8 @@ const toolBarOptions = [
tooltip: '背景填充',
name: 'background',
icon: '#icon-fill',
showDialog: true,
commandHandle: (editor, { R, G, B, A }) => setFormat(editor, path => (path.node.formats.background = `rgba(${R},${G},${B},${A})`)),
},
{
tooltip: '左对齐',
Expand Down

0 comments on commit 50c9b82

Please sign in to comment.