Skip to content

Commit

Permalink
fix: Add the necessary expose
Browse files Browse the repository at this point in the history
  • Loading branch information
rashagu committed Dec 16, 2024
1 parent cb8baa6 commit 5d7503b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 45 deletions.
9 changes: 8 additions & 1 deletion packages/semi-ui-vue/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ import TreeCheckSimpleJsonDemo from './components/tree/__test__/TreeCheckSimpleJ
import DragMoveDemo from './components/dragMove/__test__/DragMoveDemo';
import JsonViewerDemo from './components/jsonViewer/__test__/JsonViewerDemo';
import SelectTest from './components/select/__test__/SelectTest';
import { InputVModel } from './components';

export interface ExampleProps {
name?: string
Expand All @@ -189,9 +190,15 @@ const App = defineComponent<ExampleProps>((props, {slots}) => {
// })
// console.log(ConfigProvider);
const a = ref('sdsd')
const testRef = ref()
watch(testRef, (v)=>{
console.log(v, v?.getRef());
})
return () => (
<div>
<ConfigProvider locale={zh_CN}>
{a.value}
<InputVModel ref={testRef} v-model={a.value}/>
{/*<WithVModelDemo/>*/}
{/*<CalenderDemo />*/}
{/*<TransferDemo/>*/}
Expand Down Expand Up @@ -328,7 +335,7 @@ const App = defineComponent<ExampleProps>((props, {slots}) => {
{/*<SelectRenderOptionItem/>*/}
{/*<SelectDemoToRawTest/>*/}
{/*<SelectDemo/>*/}
<SelectTest/>
{/*<SelectTest/>*/}
{/*<SelectDemo2/>*/}
{/*<SelectDemo3/>*/}
{/*<SelectDemo4/>*/}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineComponent, ref, h, Fragment, useSlots } from 'vue';
import { defineComponent, ref, h, Fragment, useSlots, onMounted, nextTick } from 'vue';
import { CombineProps } from '../../interface';
import JsonViewer from '../index';

interface JsonViewerDemoProps {
name?: string;
}

const data = `{
"name": "Semi",
"version": "0.0.0"
}`;
const data = '{' +
'"name": "Semi",' +
'"version": "0.0.0"' +
'}';
export const vuePropsType: CombineProps<JsonViewerDemoProps> = {
name: String,
};
Expand All @@ -18,11 +18,17 @@ const JsonViewerDemo = defineComponent({
name: 'JsonViewerDemo',
setup(props, { attrs }) {
const slots = useSlots();
const j = ref()
onMounted(()=>{
nextTick(()=>{
// j.value?.format()
})
})


return () => (
<div style={{ marginBottom: '16px' }}>
<JsonViewer height={100} width={400} value={data} />
<JsonViewer ref={j} height={100} width={400} value={data} />
</div>
);
},
Expand Down
7 changes: 6 additions & 1 deletion packages/semi-ui-vue/src/components/jsonViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const vuePropsType = vuePropsMake(propTypes, defaultProps);
const JsonViewerCom = defineComponent({
props: { ...vuePropsType },
name: 'JsonViewerCom',
setup(props, { attrs }) {
setup(props, { expose, attrs }) {
const slots = useSlots();
const state = reactive<JsonViewerState>({
searchOptions: {
Expand Down Expand Up @@ -155,6 +155,11 @@ const JsonViewerCom = defineComponent({
foundation.jsonViewer.format();
}

expose({
getValue,
format,
})

function getStyle() {
const { width, height } = props;
return {
Expand Down
84 changes: 48 additions & 36 deletions packages/semi-ui-vue/src/components/toast/__test__/ToastDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const vuePropsType = {
}
const ToastDemo = defineComponent((props, {}) => {
const slots = useSlots()
const Toast = useToastHook()
// const Toast = useToastHook()
const id = Toast.info({
content:<div class={"test_class1"}>useToastHook</div>
})
Expand Down Expand Up @@ -46,46 +46,58 @@ const ToastDemo = defineComponent((props, {}) => {
title: 'This is a success message',
content: 123,
};
return () => (
<div>

<ToastList ref={(instance: any) => {
instance?.add({...{
motion: true,
zIndex: 1010,
content: 'test',
}, id: 'id'});
}}/>
return () => {

return <Button onClick={() => {
Toast.info('opts.value')
// setTimeout(() => {
// opts.value = {
// content: 'Hi, Bytedansssssssssssce dance dance',
// duration: 3,
// }
// }, 1000)
}}>Display Toast</Button>
return (
<div>
<Button onClick={() => {
Toast.info(opts.value)
// setTimeout(() => {
// opts.value = {
// content: 'Hi, Bytedansssssssssssce dance dance',
// duration: 3,
// }
// }, 1000)
}}>Display Toast</Button>
<br/>


<br/>
<Button onClick={throttled} className={'Throttled'}>Throttled Toast</Button>


<ToastList ref={(instance: any) => {
instance?.add({...{
motion: true,
zIndex: 1010,
content: 'test',
}, id: 'id'});
}}/>
<div>
<Button
onClick={() => {
toast_.success(config);
}}
>
Hook Toast
</Button>
<Button onClick={() => {
Toast.info(opts.value)
// setTimeout(() => {
// opts.value = {
// content: 'Hi, Bytedansssssssssssce dance dance',
// duration: 3,
// }
// }, 1000)
}}>Display Toast</Button>
<br/>


<br/>
<Button onClick={throttled} className={'Throttled'}>Throttled Toast</Button>


<div>
<Button
onClick={() => {
toast_.success(config);
}}
>
Hook Toast
</Button>
</div>
{contextHolder.value}
</div>
{contextHolder.value}
</div>
</div>
)
)
}
})


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ export default function WithVModel<T>(Comp: DefineSetupFnComponent<T>, opt?: Wit
const instance = ref();

expose({
...instance.value,
getRef(){
return instance.value
},
});
return () => {
if (props['onUpdate:modelValue']) {
return (
//@ts-ignore
<Comp
ref={instance}
{...omit(props, 'update:modelValue', 'modelValue', opt?.valueKey || 'value', 'onChange')}
{...{
[opt?.valueKey || 'value']: props.modelValue,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d7503b

Please sign in to comment.