-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts" setup> | ||
Check warning on line 1 in examples/vue3/src/components/Autoprops.story.vue GitHub Actions / Build and test
|
||
import Autoprops from './Autoprops.vue' | ||
function initState () { | ||
return { | ||
name: 'Fry', | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<Story | ||
title="Autoprops" | ||
:layout="{ | ||
type: 'grid', | ||
width: 200, | ||
}" | ||
> | ||
<Variant title="Naked"> | ||
<Autoprops /> | ||
</Variant> | ||
<Variant | ||
title="State" | ||
:init-state="initState" | ||
> | ||
<template #default="{ state }"> | ||
<Autoprops :name="state.name" /> | ||
</template> | ||
</Variant> | ||
</Story> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script lang="ts" setup> | ||
Check warning on line 1 in examples/vue3/src/components/Autoprops.vue GitHub Actions / Build and test
|
||
defineProps({ | ||
name: { | ||
type: String, | ||
default: 'world', | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
Hello {{ name }}! | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/histoire-app/src/app/components/panel/ControlsComponentState.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { Icon } from '@iconify/vue' | ||
import type { Variant } from '@histoire/shared' | ||
import ControlsComponentStateItem from './ControlsComponentStateItem.vue' | ||
const props = defineProps<{ | ||
variant: Variant | ||
}>() | ||
const stateKeys = computed(() => Object.keys(props.variant.state || {}) | ||
.filter((key) => !key.startsWith('_h'))) | ||
</script> | ||
|
||
<template> | ||
<div class="histoire-controls-component-init-state"> | ||
<div class="htw-p-2 htw-flex htw-items-center htw-gap-1"> | ||
<Icon | ||
v-tooltip="'Auto-detected state'" | ||
icon="carbon:data-vis-1" | ||
class="htw-w-4 htw-h-4 htw-text-primary-500 htw-flex-none" | ||
/> | ||
<div> | ||
State | ||
</div> | ||
</div> | ||
<ControlsComponentStateItem | ||
v-for="key of stateKeys" | ||
:key="key" | ||
:item="key" | ||
:variant="variant" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
34 changes: 34 additions & 0 deletions
34
packages/histoire-app/src/app/components/panel/ControlsComponentStateItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script lang="ts" setup> | ||
import { computed } from 'vue' | ||
import { HstCheckbox, HstJson, HstNumber, HstText } from '@histoire/controls' | ||
import type { Variant } from '../../types' | ||
const props = defineProps<{ | ||
variant: Variant | ||
item: string | ||
}>() | ||
const comp = computed(() => { | ||
switch (typeof props.variant.state[props.item]) { | ||
case 'string': | ||
return HstText | ||
case 'number': | ||
return HstNumber | ||
case 'boolean': | ||
return HstCheckbox | ||
case 'object': | ||
default: | ||
return HstJson | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="comp" | ||
v-if="comp" | ||
v-model="variant.state[props.item]" | ||
Check failure on line 30 in packages/histoire-app/src/app/components/panel/ControlsComponentStateItem.vue GitHub Actions / Build and test
|
||
class="histoire-controls-component-prop-item" | ||
:title="props.item" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters