Skip to content

Commit

Permalink
release(setting): v0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Aug 29, 2023
1 parent 12612e9 commit 8b535ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion index.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
"setting": {
"install": true,
"react": true,
"version": "0.9.0",
"version": "0.9.1",
"style": true,
"icon": false,
"test": true,
Expand Down
10 changes: 10 additions & 0 deletions src/setting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ const progress = (val: number, min: number, max: number) => {

export class LunaSettingCheckbox extends LunaSettingItem {
private $input: $.$
private input: HTMLInputElement
constructor(
setting: Setting,
key: string,
Expand All @@ -520,6 +521,11 @@ export class LunaSettingCheckbox extends LunaSettingItem {

$input.on('change', () => this.onChange(input.checked))
this.$input = $input
this.input = input
}
setValue(value: boolean) {
this.input.checked = value
this.value = value
}
disable() {
super.disable()
Expand Down Expand Up @@ -559,6 +565,10 @@ export class LunaSettingSelect extends LunaSettingItem {
this.setOptions(options)
$select.on('change', () => this.onChange($select.val()))
}
setValue(value: string) {
this.$select.val(value)
this.value = value
}
setOptions(options: types.PlainObj<string>) {
this.$select.html(
map(
Expand Down
2 changes: 1 addition & 1 deletion src/setting/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setting",
"version": "0.9.0",
"version": "0.9.1",
"description": "Settings panel",
"dependencies": {
"micromark": "^3.1.0"
Expand Down
29 changes: 23 additions & 6 deletions src/setting/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PropsWithChildren,
ReactElement,
cloneElement,
isValidElement,
useEffect,
useRef,
} from 'react'
Expand Down Expand Up @@ -51,11 +52,13 @@ const LunaSetting: FC<PropsWithChildren<ISettingProps>> = (props) => {

return (
<div className={props.className || ''} ref={settingRef}>
{Children.map(props.children, (child) =>
cloneElement(child as ReactElement, {
setting: setting.current,
})
)}
{Children.map(props.children, (child) => {
if (isValidElement(child)) {
return cloneElement(child as ReactElement, {
setting: setting.current,
})
}
})}
</div>
)
}
Expand Down Expand Up @@ -144,6 +147,12 @@ export const LunaSettingSelect: FC<ISettingSelectProps> = (props) => {
[props.disabled]
)

useEffect(() => {
if (settingSelect.current) {
settingSelect.current.setValue(props.value)
}
}, [props.value])

useEffect(() => {
if (settingSelect.current) {
settingSelect.current.setOptions(props.options)
Expand Down Expand Up @@ -246,6 +255,12 @@ export const LunaSettingCheckbox: FC<ISettingCheckboxProps> = (props) => {
[props.disabled]
)

useEffect(() => {
if (settingCheckbox.current) {
settingCheckbox.current.setValue(props.value)
}
}, [props.value])

return null
}

Expand Down Expand Up @@ -280,7 +295,9 @@ export const LunaSettingText: FC<ISettingTextProps> = (props) => {
return null
}

export const LunaSettingHtml: FC<PropsWithChildren<ISettingItemProps>> = (props) => {
export const LunaSettingHtml: FC<PropsWithChildren<ISettingItemProps>> = (
props
) => {
const settingHtml = useRef<SettingHtml>()
const forceUpdate = useForceUpdate()

Expand Down

0 comments on commit 8b535ac

Please sign in to comment.