|
| 1 | +import { |
| 2 | + defineBadgeComponents, |
| 3 | + defineButtonComponents, |
| 4 | + defineFlexComponents, |
| 5 | + defineFormComponents, |
| 6 | + defineIconComponents, |
| 7 | + definePanelComponents, |
| 8 | +} from '@purestack/ts-components' |
| 9 | +import { tabler_rocket } from '@purestack/ts-svg-icons' |
| 10 | +import { |
| 11 | + batch, |
| 12 | + type ComputedRef, |
| 13 | + computed, |
| 14 | + createApp, |
| 15 | + defineComponent, |
| 16 | + html, |
| 17 | + type Ref, |
| 18 | + ref, |
| 19 | +} from 'regor' |
| 20 | + |
| 21 | +export interface Task { |
| 22 | + id: string |
| 23 | + title: string |
| 24 | + done: Ref<boolean> |
| 25 | +} |
| 26 | + |
| 27 | +export interface TaskRow { |
| 28 | + task: Task |
| 29 | +} |
| 30 | + |
| 31 | +const taskRow = defineComponent<TaskRow>( |
| 32 | + html`<FormCheck :id="'launch-' + task.id" :label="task.title" :checked="task.done" />`, |
| 33 | + { props: ['task'] }, |
| 34 | +) |
| 35 | + |
| 36 | +export interface LaunchChecklist { |
| 37 | + tasks: Task[] |
| 38 | + completed: ComputedRef<number> |
| 39 | + ready: ComputedRef<boolean> |
| 40 | + launched: Ref<boolean> |
| 41 | + launch: () => void |
| 42 | + reset: () => void |
| 43 | +} |
| 44 | + |
| 45 | +const launchChecklistTemplate = html`<Panel tone="neutral" variant="surfaceAlt" bodyClass="p-3"> |
| 46 | + <Flex direction="column"> |
| 47 | + <Flex justify="between" align="center" wrap="true"> |
| 48 | + <strong>Launch checklist</strong> |
| 49 | + <Badge :tone="ready ? 'success' : 'warning'" variant="surface"> |
| 50 | + {{ completed }} of {{ tasks.length }} done |
| 51 | + </Badge> |
| 52 | + </Flex> |
| 53 | + <TaskRow r-for="task in tasks" :task="task" /> |
| 54 | + <Flex wrap="true"> |
| 55 | + <Btn tone="accent" icon="tabler:rocket" :disabled="!ready || launched" @click="launch">Launch</Btn> |
| 56 | + <Btn tone="neutral" variant="surface" @click="reset">Start over</Btn> |
| 57 | + </Flex> |
| 58 | + <FormStatus r-if="launched" role="status">Launched. Every check passed.</FormStatus> |
| 59 | + </Flex> |
| 60 | +</Panel>` |
| 61 | + |
| 62 | +function createLaunchChecklist(): LaunchChecklist { |
| 63 | + const tasks: Task[] = [ |
| 64 | + { id: 'docs', title: 'Docs reviewed', done: ref(true) }, |
| 65 | + { id: 'tests', title: 'Tests passing', done: ref(false) }, |
| 66 | + { id: 'notes', title: 'Release notes written', done: ref(false) }, |
| 67 | + ] |
| 68 | + const launched = ref(false) |
| 69 | + const completed = computed(() => tasks.filter((task) => task.done()).length) |
| 70 | + const ready = computed(() => completed() === tasks.length) |
| 71 | + return { |
| 72 | + tasks, |
| 73 | + completed, |
| 74 | + ready, |
| 75 | + launched, |
| 76 | + launch: () => launched(true), |
| 77 | + reset: () => |
| 78 | + batch(() => { |
| 79 | + for (const task of tasks) task.done(false) |
| 80 | + launched(false) |
| 81 | + }), |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +createApp( |
| 86 | + { |
| 87 | + components: { |
| 88 | + LaunchChecklist: defineComponent<LaunchChecklist>( |
| 89 | + launchChecklistTemplate, |
| 90 | + { context: createLaunchChecklist }, |
| 91 | + ), |
| 92 | + TaskRow: taskRow, |
| 93 | + ...defineBadgeComponents(), |
| 94 | + ...defineButtonComponents(), |
| 95 | + ...defineFlexComponents(), |
| 96 | + ...defineFormComponents(), |
| 97 | + ...defineIconComponents((name) => |
| 98 | + name === 'tabler:rocket' ? tabler_rocket : '', |
| 99 | + ), |
| 100 | + ...definePanelComponents(), |
| 101 | + }, |
| 102 | + }, |
| 103 | + { selector: 'app#launch-checklist', template: html`<LaunchChecklist />` }, |
| 104 | +) |
0 commit comments