Skip to content

Commit f0d4b44

Browse files
committed
fix: extend alert support on action
1 parent 2058af6 commit f0d4b44

File tree

11 files changed

+87
-28
lines changed

11 files changed

+87
-28
lines changed
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import type { Meta, StoryObj } from "@storybook/vue3";
22

3-
import Button from "./Button.vue";
3+
import ButtonComponent from "./Button.vue";
4+
import { eColors } from "@open-xamu-co/ui-common-enums";
45

56
const meta = {
67
title: "Action/Action Button",
7-
component: Button as Record<keyof typeof Button, unknown>,
8+
component: ButtonComponent as Record<keyof typeof ButtonComponent, unknown>,
89
args: { default: "Action Button" },
9-
} satisfies Meta<typeof Button>;
10+
} satisfies Meta<typeof ButtonComponent>;
1011

11-
type Story = StoryObj<typeof Button>;
12+
type Story = StoryObj<typeof ButtonComponent>;
1213

13-
export const Sample: Story = {
14+
export const Button: Story = {
1415
args: { default: "Action Button" },
1516
};
1617

18+
export const ButtonIsActiveWithAlert: Story = {
19+
args: { default: "Button with alert", active: true, alert: true },
20+
};
21+
22+
export const ButtonAsY: Story = {
23+
args: { default: "⋮", y: true, theme: eColors.DANGER },
24+
};
25+
26+
export const ButtonAsYIsActiveWithAlert: Story = {
27+
args: { default: "⋮", y: true, theme: eColors.DANGER, active: true, alert: true },
28+
};
29+
1730
export default meta;

packages/components-vue/src/components/action/Button.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<template>
22
<BaseAction
33
v-bind="{ ...$attrs, ...props, ...tooltipAttributes }"
4-
:class="[modifiersClasses, stateClasses, themeClasses]"
5-
class="bttn"
4+
:class="[modifiersClasses, stateClasses, themeClasses, buttonTypeClass]"
65
>
76
<slot></slot>
87
</BaseAction>
98
</template>
109

1110
<script setup lang="ts">
11+
import { computed } from "vue";
12+
1213
import BaseAction from "../base/Action.vue";
1314
1415
import type {
@@ -27,7 +28,12 @@
2728
iUseModifiersProps,
2829
iUseStateProps,
2930
iUseThemeProps,
30-
iUseThemeTooltipProps {}
31+
iUseThemeTooltipProps {
32+
/**
33+
* Use vertical button
34+
*/
35+
y?: boolean;
36+
}
3137
3238
/**
3339
* Action Button Component
@@ -44,4 +50,8 @@
4450
const { modifiersClasses } = useModifiers(props);
4551
const { stateClasses } = useState(props);
4652
const { themeClasses, tooltipAttributes } = useTheme(props, true);
53+
54+
const buttonTypeClass = computed(() => {
55+
return props.y ? "bttnY" : "bttn";
56+
});
4757
</script>

packages/components-vue/src/components/form/Simple.stories.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Meta, StoryObj } from "@storybook/vue3";
22

3-
import Simple from "./Simple.vue";
3+
import SimpleComponent from "./Simple.vue";
44
import { FormInput } from "@open-xamu-co/ui-common-helpers";
55
import { eFormType } from "@open-xamu-co/ui-common-enums";
66

@@ -55,17 +55,17 @@ const inputs: FormInput[] = [
5555

5656
const meta = {
5757
title: "Form/Form Simple",
58-
component: Simple as Record<keyof typeof Simple, unknown>,
58+
component: SimpleComponent as Record<keyof typeof SimpleComponent, unknown>,
5959
args: { modelValue: inputs },
60-
} satisfies Meta<typeof Simple>;
60+
} satisfies Meta<typeof SimpleComponent>;
6161

62-
type Story = StoryObj<typeof Simple>;
62+
type Story = StoryObj<typeof SimpleComponent>;
6363

64-
export const Sample: Story = {
64+
export const Form: Story = {
6565
args: { modelValue: inputs },
6666
};
6767

68-
export const WithLocation: Story = {
68+
export const FormUsingLocationField: Story = {
6969
args: {
7070
modelValue: [
7171
new FormInput({
@@ -78,7 +78,7 @@ export const WithLocation: Story = {
7878
},
7979
};
8080

81-
export const WithPhone: Story = {
81+
export const FormUsingPhoneField: Story = {
8282
args: {
8383
modelValue: [
8484
new FormInput({

packages/components-vue/src/components/form/Stages.stories.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { type iForm, FormInput, useForm } from "@open-xamu-co/ui-common-helpers"
44
import { eFormType } from "@open-xamu-co/ui-common-enums";
55
import type { iInvalidInput } from "@open-xamu-co/ui-common-types";
66

7-
import Stages from "./Stages.vue";
7+
import StagesComponent from "./Stages.vue";
88

9-
export const stages: iForm[][] = [
9+
export const stagesData: iForm[][] = [
1010
[
1111
{
1212
title: "Offer field",
@@ -97,17 +97,18 @@ async function submitFn(inputs: FormInput[]): Promise<boolean | iInvalidInput[]>
9797

9898
const meta = {
9999
title: "Form/Form Stages",
100-
component: Stages,
101-
args: { stages, submitFn },
102-
} satisfies Meta<typeof Stages>;
100+
component: StagesComponent,
101+
args: { stages: stagesData, submitFn },
102+
excludeStories: /.*Data$/,
103+
} satisfies Meta<typeof StagesComponent>;
103104

104-
type Story = StoryObj<typeof Stages>;
105+
type Story = StoryObj<typeof StagesComponent>;
105106

106-
export const Sample: Story = {
107-
args: { stages, submitFn },
107+
export const Stages: Story = {
108+
args: { stages: stagesData, submitFn },
108109
};
109110

110-
export const WithInvalidStage: Story = {
111+
export const StagesWithInvalidStage: Story = {
111112
args: {
112113
stages: [
113114
[

packages/components-vue/src/composables/state.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ export default function useState(props: iUseStateProps) {
1515

1616
const stateClasses = computed<string[]>(() => {
1717
const values: Record<string, boolean>[] = [
18-
{ ...props.state, active: !!props.active, invalid: !!props.invalid },
18+
{
19+
...props.state,
20+
active: !!props.active,
21+
alert: !!props.alert,
22+
invalid: !!props.invalid,
23+
},
1924
];
2025

21-
return props.state || props.active || props.invalid ? GMC(values, { prefix: "is" }) : [];
26+
const hasState = !!(props.state || props.active || props.alert || props.invalid);
27+
28+
return hasState ? GMC(values, { prefix: "is" }) : [];
2229
});
2330

2431
return { stateClasses };

packages/components-vue/src/screens/ModalWithFormStages.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import FormStages from "../components/form/Stages.vue";
5353
import Modal from "../components/modal/Simple.vue";
5454
55-
import { stages as formStages } from "../components/form/Stages.stories";
55+
import { stagesData } from "../components/form/Stages.stories";
5656
5757
/**
5858
* Modal with form stages
@@ -61,7 +61,7 @@
6161
*/
6262
6363
const stages = computed<iForm[][]>(() => {
64-
return formStages;
64+
return stagesData;
6565
});
6666
6767
function updateUiComponentId({ uiComponent }: Record<string, any[]>) {

packages/components-vue/src/types/props.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ export interface iUseModifiersProps {
1717
}
1818

1919
export interface iUseStateProps {
20+
/**
21+
* Alert state: Mostly useful on actions
22+
* Included here to make his usage less verbose
23+
*
24+
* @state
25+
* @example is--alert
26+
*/
27+
alert?: boolean;
2028
/**
2129
* Active state: Mostly useful on actions
2230
* Included here to make his usage less verbose

packages/styles/src/components/action/_box.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
@mixin box {
1212
@layer definitions {
1313
.#{module.$component-box} {
14+
@include module.action-alert-styles;
1415
@include module.action-disabled-styles;
1516

1617
// width: 100%;
1718
box-sizing: border-box;
1819
border: 2px solid transparent;
1920
overflow: visible;
2021

22+
&.#{module.$status-is-alert}:after {
23+
background-color: var(--bg, transparent);
24+
}
25+
2126
@layer defaults {
2227
&:not(
2328
.#{module.$prefix-default}--button,

packages/styles/src/components/action/_button.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
@include module.action-round-styles;
1414
@include module.action-aligment-styles;
1515
@include module.action-gaping-styles;
16+
@include module.action-alert-styles;
1617
@include module.action-theme-union-styles;
1718
@include module.action-size-styles;
1819
@include module.action-border-styles;
1920
@include module.action-capitalize-styles;
2021
@include module.action-disabled-styles(false);
22+
23+
&.#{module.$status-is-alert}:after {
24+
--bc: var(--bg);
25+
26+
background-color: var(--bg-a, #{module.$color-bg});
27+
}
2128
}
2229

2330
:not([class*="#{module.$status-toggle}"])

packages/styles/src/components/action/_buttonY.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
.#{module.$component-button-y} {
1010
@include module.action-styles;
1111
@include module.action-aligment-styles;
12+
@include module.action-alert-styles;
13+
14+
&.#{module.$status-is-alert}:after {
15+
--bc: var(--bg);
16+
17+
background-color: var(--bg-a, #{module.$color-bg});
18+
}
1219

1320
@include module.action-size-styles(false) using($size) {
1421
padding: #{$size * 0.8} #{$size * 0.2};

0 commit comments

Comments
 (0)