Skip to content

Commit

Permalink
feat: update programmatic oruga
Browse files Browse the repository at this point in the history
  • Loading branch information
mlmoravek committed Sep 29, 2023
1 parent 33f2cd5 commit ea7661c
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { ref, onBeforeMount, onBeforeUnmount } from "vue";
import { useProgrammatic } from "../../../../../oruga-next/dist/oruga";
import { useOruga } from "../../../../../oruga-next/dist/oruga";
const customIconConfig = {
iconComponent: undefined,
Expand Down Expand Up @@ -38,7 +38,7 @@ const customIconConfig = {
const docsIcon = ref();
const { oruga } = useProgrammatic();
const oruga = useOruga();
onBeforeMount(() => {
docsIcon.value = oruga.config.getOptions().iconComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script setup>
import { ref } from "vue";
import { useProgrammatic } from "../../../../../oruga-next/dist/oruga";
import { useOruga } from "../../../../../oruga-next/dist/oruga";
const isFullPage = ref(true);
const oruga = useOruga();
const elementRef = ref();
const { oruga } = useProgrammatic();
const isFullPage = ref(true);
function openLoading() {
const loadingComponent = oruga.loading.open({
fullPage: isFullPage.value,
container: isFullPage.value ? null : this.$refs.element,
container: isFullPage.value ? null : elementRef.value,
});
setTimeout(() => loadingComponent.close(), 3 * 1000);
}
Expand All @@ -29,7 +31,7 @@ function openLoading() {
Display loader over full page
</o-switch>
</o-field>
<p ref="element" style="position: relative">
<p ref="elementRef" style="position: relative">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce id
fermentum quam. Proin sagittis, nibh id hendrerit imperdiet, elit
sapien laoreet elit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup>
import { useProgrammatic } from "../../../../../oruga-next/dist/oruga";
import { useOruga } from "../../../../../oruga-next/dist/oruga";
import ModalForm from "./_modal-form-async.vue";
const { oruga } = useProgrammatic();
const oruga = useOruga();
const promptModal = async () => {
const instance = oruga.modal.open({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup>
import { h } from "vue";
import { useProgrammatic } from "../../../../../oruga-next/dist/oruga";
import { useOruga } from "../../../../../oruga-next/dist/oruga";
import ModalForm from "./_modal-form.vue";
const { oruga } = useProgrammatic();
const oruga = useOruga();
function imageModal() {
const vnode = h("p", { style: { "text-align": "center" } }, [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup>
import { useProgrammatic } from "../../../../../oruga-next/dist/oruga";
import { useOruga } from "../../../../../oruga-next/dist/oruga";
import NotificationForm from "./_notification-form.vue";
const { oruga } = useProgrammatic();
const oruga = useOruga();
function simple() {
oruga.notification.open("Something happened");
Expand Down
6 changes: 3 additions & 3 deletions packages/docs-next/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ExampleViewer from "./components/ExampleViewer.vue";
import Expo from "./components/Expo.vue";
import Carbon from "./components/Carbon.vue";

import Oruga, { useProgrammatic } from "../../../oruga-next/dist/oruga";
import Oruga, { useOruga } from "../../../oruga-next/dist/oruga";

import { bulmaConfig } from "@oruga-ui/theme-bulma";
import { bootstrapConfig } from "@oruga-ui/theme-bootstrap";
Expand Down Expand Up @@ -101,14 +101,14 @@ export default {
case "theme-bulma": {
bulmaConfig.iconPack = "fas";
bulmaConfig.iconComponent = "vue-fontawesome";
const { oruga } = useProgrammatic() as any;
const { oruga } = useOruga();
oruga.config.setOptions(bulmaConfig);
break;
}
case "theme-bootstrap": {
bootstrapConfig.iconPack = "fas";
bootstrapConfig.iconComponent = "vue-fontawesome";
const { oruga } = useProgrammatic() as any;
const { oruga } = useOruga();
oruga.config.setOptions(bootstrapConfig);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-next/documentation/customisation.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ You can also add and override classes to a component directly using class proper
As alternative Oruga allows to customize each components providing and overriding the `Config` object programmatically:
```js
import { useProgrammatic } from '@oruga-ui/oruga-next';
import { useOruga } from '@oruga-ui/oruga-next';

const { oruga } = useProgrammatic();
const oruga = useOruga();

const config = oruga.config.getOptions();

Expand Down
4 changes: 2 additions & 2 deletions packages/oruga-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"vite": "^4.4.9",
"vite-plugin-dts": "^3.5.4",
"vite-plugin-istanbul": "^5.0.0",
"vite-tsconfig-paths": "^4.2.1",
"vue": "^3.2.45",
"vite-tsconfig-paths": "^4.2.1",
"vue": "^3.3.4",
"vue-tsc": "^1.8.11"
},
"nyc": {
Expand Down
29 changes: 18 additions & 11 deletions packages/oruga-next/src/components/loading/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,47 @@ import { createVNode, render } from "vue";

import Loading from "./Loading.vue";

import { VueInstance } from "../../utils/config";
import { merge } from "../../utils/helpers";
import { VueInstance } from "@/utils/config";
import { merge } from "@/utils/helpers";
import {
registerComponent,
registerComponentProgrammatic,
} from "../../utils/plugins";
import InstanceRegistry from "../../utils/InstanceRegistry";
} from "@/utils/plugins";
import InstanceRegistry from "@/utils/InstanceRegistry";

declare module "@/types" {
interface OrugaPrgrammatic {
loading: typeof LoadingProgrammatic;
}
}

let localVueInstance: App;

const instances = new InstanceRegistry();
const instances = new InstanceRegistry<typeof Loading>();

const LoadingProgrammatic = {
open(
params: Readonly<ComponentPropsOptions>,
): InstanceType<typeof Loading> {
const defaultParam = {
const defaultParams = {
programmatic: { instances },
active: true,
};
const propsData = merge(defaultParam, params);

const propsData = merge(defaultParams, params);
propsData.promise = new Promise((p1, p2) => {
propsData.programmatic.resolve = p1;
propsData.programmatic.reject = p2;
});

const app = localVueInstance || VueInstance;
const vnode = createVNode(Loading, propsData);
vnode.appContext = app._context;
render(vnode, document.createElement("div"));
return vnode.component.proxy as InstanceType<typeof Loading>;
},
closeAll(...args: any[]) {
instances.walk((entry) => {
entry.close(...args);
});
closeAll(...args: any[]): void {
instances.walk((entry) => entry.close(...args));
},
};

Expand Down
32 changes: 18 additions & 14 deletions packages/oruga-next/src/components/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import { createVNode, render } from "vue";

import Modal from "./Modal.vue";

import { VueInstance } from "../../utils/config";
import { merge } from "../../utils/helpers";
import { VueInstance } from "@/utils/config";
import { merge } from "@/utils/helpers";
import {
registerComponent,
registerComponentProgrammatic,
} from "../../utils/plugins";
import InstanceRegistry from "../../utils/InstanceRegistry";
} from "@/utils/plugins";
import InstanceRegistry from "@/utils/InstanceRegistry";

declare module "@/types" {
interface OrugaPrgrammatic {
modal: typeof ModalProgrammatic;
}
}

let localVueInstance: App;

const instances = new InstanceRegistry();
const instances = new InstanceRegistry<typeof Modal>();

const ModalProgrammatic = {
open(params: OModal | string): InstanceType<typeof Modal> {
Expand All @@ -26,33 +32,31 @@ const ModalProgrammatic = {
newParams = params;
}

const defaultParam = {
const defaultParams = {
programmatic: { instances },
};

let slot;
if (Array.isArray(newParams.content)) {
slot = newParams.content;
delete newParams.content;
}
const propsData = merge(defaultParam, newParams);

const propsData = merge(defaultParams, newParams);
propsData.promise = new Promise((p1, p2) => {
propsData.programmatic.resolve = p1;
propsData.programmatic.reject = p2;
});
const defaultSlot = () => slot;

const app = localVueInstance || VueInstance;
const defaultSlot = () => {
return slot;
};
const vnode = createVNode(Modal, propsData, defaultSlot);
vnode.appContext = app._context;
render(vnode, document.createElement("div"));
return vnode.component.proxy as InstanceType<typeof Modal>;
},
closeAll(...args: any[]) {
instances.walk((entry) => {
entry.close(...args);
});
closeAll(...args: any[]): void {
instances.walk((entry) => entry.close(...args));
},
};

Expand Down
49 changes: 23 additions & 26 deletions packages/oruga-next/src/components/notification/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import type { App, DefineComponent, Plugin } from "vue";
import { createVNode, render } from "vue";

import Notification from "./Notification.vue";
import NotificationNotice from "./NotificationNotice.vue";

import { getOptions } from "../../utils/config";
import { getValueByPath } from "../../utils/helpers";
import { merge } from "../../utils/helpers";
import { VueInstance } from "../../utils/config";
import { VueInstance, getOption } from "@/utils/config";
import { merge } from "@/utils/helpers";
import {
registerComponent,
registerComponentProgrammatic,
} from "../../utils/plugins";
import InstanceRegistry from "../..//utils/InstanceRegistry";
} from "@/utils/plugins";
import InstanceRegistry from "@//utils/InstanceRegistry";

import type { App, DefineComponent, Plugin } from "vue";
import { createVNode, render } from "vue";
declare module "@/types" {
interface OrugaPrgrammatic {
notification: typeof NotificationProgrammatic;
}
}

let localVueInstance: App;

const instances = new InstanceRegistry();
const instances = new InstanceRegistry<typeof NotificationNotice>();

const NotificationProgrammatic = {
open(params): InstanceType<typeof NotificationNotice> {
Expand All @@ -29,45 +33,38 @@ const NotificationProgrammatic = {
newParams = params;
}

const defaultParam = {
const defaultParams = {
programmatic: { instances },
position: getValueByPath(
getOptions(),
"notification.position",
"top-right",
),
position: getOption("notification.position", "top-right"),
closable:
params.closable ||
getValueByPath(getOptions(), "notification.closable", false),
params.closable || getOption("notification.closable", false),
};

let slot;
if (Array.isArray(newParams.message)) {
slot = newParams.message;
delete newParams.message;
}

newParams.active = true;
const propsData = merge(defaultParam, newParams);
const propsData = merge(defaultParams, newParams);
propsData.promise = new Promise((p1, p2) => {
propsData.programmatic.resolve = p1;
propsData.programmatic.reject = p2;
});

const app = localVueInstance || VueInstance;
propsData.propsNotification = Object.assign({}, propsData);
propsData.propsNotification.isActive = true;
const defaultSlot = () => {
return slot;
};
const defaultSlot = () => slot;

const app = localVueInstance || VueInstance;
const vnode = createVNode(NotificationNotice, propsData, defaultSlot);
vnode.appContext = app._context;
render(vnode, document.createElement("div"));
return vnode.component.proxy as InstanceType<typeof NotificationNotice>;
},
closeAll(...args: any[]) {
instances.walk((entry) => {
entry.close(...args);
});
closeAll(...args: any[]): void {
instances.walk((entry) => entry.close(...args));
},
};

Expand Down
Loading

0 comments on commit ea7661c

Please sign in to comment.