@ttoss/components 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @ttoss/components
2
+
3
+ ## 📚 About
4
+
5
+ <strong>@ttoss/components</strong> is a set of React components that you can use to build your apps.
6
+
7
+ ## 🚀 Getting Started
8
+
9
+ ### Install @ttoss/components
10
+
11
+ ```shell
12
+ $ yarn add @ttoss/components
13
+ # or
14
+ $ npm install @ttoss/components
15
+ ```
@@ -0,0 +1,63 @@
1
+ // tsup.inject.js
2
+ import * as React from "react";
3
+
4
+ // src/components/InstallPwa/InstallPwa.tsx
5
+ import * as React2 from "react";
6
+
7
+ // src/components/InstallPwa/InstallPwaUi.tsx
8
+ import { Button, Flex, Text } from "@ttoss/ui";
9
+ var InstallPwaUi = ({ onInstall }) => {
10
+ return /* @__PURE__ */ React.createElement(Flex, {
11
+ sx: {
12
+ position: "absolute",
13
+ bottom: 4,
14
+ width: "100%",
15
+ justifyContent: "center"
16
+ }
17
+ }, /* @__PURE__ */ React.createElement(Flex, {
18
+ sx: {
19
+ backgroundColor: "background",
20
+ justifyContent: "center",
21
+ alignItems: "center",
22
+ gap: 3,
23
+ width: "auto",
24
+ border: "1px solid",
25
+ borderColor: "muted",
26
+ borderRadius: 1,
27
+ padding: 4
28
+ }
29
+ }, /* @__PURE__ */ React.createElement(Text, null, "Deseja instalar o nosso aplicativo?"), /* @__PURE__ */ React.createElement(Button, {
30
+ onClick: onInstall
31
+ }, "Instalar")));
32
+ };
33
+
34
+ // src/components/InstallPwa/InstallPwa.tsx
35
+ var InstallPwa = () => {
36
+ const [supportsPwa, setSupportsPwa] = React2.useState(false);
37
+ const [promptInstall, setPromptInstall] = React2.useState(null);
38
+ React2.useEffect(() => {
39
+ const handler = (e) => {
40
+ e.preventDefault();
41
+ setSupportsPwa(true);
42
+ setPromptInstall(e);
43
+ };
44
+ window.addEventListener("beforeinstallprompt", handler);
45
+ return () => window.removeEventListener("transitionend", handler);
46
+ }, []);
47
+ const onInstall = (e) => {
48
+ e.preventDefault();
49
+ if (!promptInstall) {
50
+ return;
51
+ }
52
+ promptInstall.prompt();
53
+ };
54
+ if (!supportsPwa) {
55
+ return null;
56
+ }
57
+ return /* @__PURE__ */ React2.createElement(InstallPwaUi, {
58
+ onInstall
59
+ });
60
+ };
61
+ export {
62
+ InstallPwa
63
+ };
@@ -0,0 +1,3 @@
1
+ declare const InstallPwa: () => JSX.Element | null;
2
+
3
+ export { InstallPwa };
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __reExport = (target, module2, copyDefault, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ }
18
+ return target;
19
+ };
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
+ };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
+
29
+ // src/index.ts
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ InstallPwa: () => InstallPwa
33
+ });
34
+
35
+ // tsup.inject.js
36
+ var React = __toESM(require("react"));
37
+
38
+ // src/components/InstallPwa/InstallPwa.tsx
39
+ var React2 = __toESM(require("react"));
40
+
41
+ // src/components/InstallPwa/InstallPwaUi.tsx
42
+ var import_ui = require("@ttoss/ui");
43
+ var InstallPwaUi = ({ onInstall }) => {
44
+ return /* @__PURE__ */ React.createElement(import_ui.Flex, {
45
+ sx: {
46
+ position: "absolute",
47
+ bottom: 4,
48
+ width: "100%",
49
+ justifyContent: "center"
50
+ }
51
+ }, /* @__PURE__ */ React.createElement(import_ui.Flex, {
52
+ sx: {
53
+ backgroundColor: "background",
54
+ justifyContent: "center",
55
+ alignItems: "center",
56
+ gap: 3,
57
+ width: "auto",
58
+ border: "1px solid",
59
+ borderColor: "muted",
60
+ borderRadius: 1,
61
+ padding: 4
62
+ }
63
+ }, /* @__PURE__ */ React.createElement(import_ui.Text, null, "Deseja instalar o nosso aplicativo?"), /* @__PURE__ */ React.createElement(import_ui.Button, {
64
+ onClick: onInstall
65
+ }, "Instalar")));
66
+ };
67
+
68
+ // src/components/InstallPwa/InstallPwa.tsx
69
+ var InstallPwa = () => {
70
+ const [supportsPwa, setSupportsPwa] = React2.useState(false);
71
+ const [promptInstall, setPromptInstall] = React2.useState(null);
72
+ React2.useEffect(() => {
73
+ const handler = (e) => {
74
+ e.preventDefault();
75
+ setSupportsPwa(true);
76
+ setPromptInstall(e);
77
+ };
78
+ window.addEventListener("beforeinstallprompt", handler);
79
+ return () => window.removeEventListener("transitionend", handler);
80
+ }, []);
81
+ const onInstall = (e) => {
82
+ e.preventDefault();
83
+ if (!promptInstall) {
84
+ return;
85
+ }
86
+ promptInstall.prompt();
87
+ };
88
+ if (!supportsPwa) {
89
+ return null;
90
+ }
91
+ return /* @__PURE__ */ React2.createElement(InstallPwaUi, {
92
+ onInstall
93
+ });
94
+ };
95
+ module.exports = __toCommonJS(src_exports);
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ InstallPwa
99
+ });
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@ttoss/components",
3
+ "version": "1.8.0",
4
+ "description": "React components.",
5
+ "license": "UNLICENSED",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "dist/index.js",
10
+ "typings": "dist/index.d.ts",
11
+ "module": "dist/esm/index.js",
12
+ "files": [
13
+ "dist",
14
+ "src"
15
+ ],
16
+ "keywords": [
17
+ "React",
18
+ "components"
19
+ ],
20
+ "author": "ttoss",
21
+ "contributors": [
22
+ {
23
+ "email": "pedro@arantespp.com",
24
+ "name": "Pedro Arantes",
25
+ "url": "https://arantespp.com/contact"
26
+ }
27
+ ],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "test": "jest",
31
+ "dev": "yarn workspace @docs/storybook run dev"
32
+ },
33
+ "dependencies": {
34
+ "@ttoss/ui": "^1.8.0"
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=17.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@ttoss/config": "^1.8.0",
41
+ "@ttoss/test-utils": "^1.8.0"
42
+ },
43
+ "gitHead": "cc80acf9bb493d047b7bc4d951bd0c1c6875def3"
44
+ }
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+
3
+ import { InstallPwaUi } from './InstallPwaUi';
4
+
5
+ export const InstallPwa = () => {
6
+ const [supportsPwa, setSupportsPwa] = React.useState(false);
7
+ const [promptInstall, setPromptInstall] = React.useState<any>(null);
8
+
9
+ React.useEffect(() => {
10
+ const handler = (e: any) => {
11
+ e.preventDefault();
12
+ setSupportsPwa(true);
13
+ setPromptInstall(e);
14
+ };
15
+
16
+ window.addEventListener('beforeinstallprompt', handler);
17
+
18
+ return () => window.removeEventListener('transitionend', handler);
19
+ }, []);
20
+
21
+ const onInstall = (e: any) => {
22
+ e.preventDefault();
23
+ if (!promptInstall) {
24
+ return;
25
+ }
26
+ promptInstall.prompt();
27
+ };
28
+
29
+ if (!supportsPwa) {
30
+ return null;
31
+ }
32
+
33
+ return <InstallPwaUi onInstall={onInstall} />;
34
+ };
@@ -0,0 +1,35 @@
1
+ import { Button, Flex, Text } from '@ttoss/ui';
2
+
3
+ export type InstallPwaUiProps = {
4
+ onInstall: React.MouseEventHandler<HTMLButtonElement>;
5
+ };
6
+
7
+ export const InstallPwaUi = ({ onInstall }: InstallPwaUiProps) => {
8
+ return (
9
+ <Flex
10
+ sx={{
11
+ position: 'absolute',
12
+ bottom: 4,
13
+ width: '100%',
14
+ justifyContent: 'center',
15
+ }}
16
+ >
17
+ <Flex
18
+ sx={{
19
+ backgroundColor: 'background',
20
+ justifyContent: 'center',
21
+ alignItems: 'center',
22
+ gap: 3,
23
+ width: 'auto',
24
+ border: '1px solid',
25
+ borderColor: 'muted',
26
+ borderRadius: 1,
27
+ padding: 4,
28
+ }}
29
+ >
30
+ <Text>Deseja instalar o nosso aplicativo?</Text>
31
+ <Button onClick={onInstall}>Instalar</Button>
32
+ </Flex>
33
+ </Flex>
34
+ );
35
+ };
@@ -0,0 +1,5 @@
1
+ import * as componentsModule from './index';
2
+
3
+ test('should export components', () => {
4
+ expect(componentsModule.InstallPwa).toBeDefined();
5
+ });
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { InstallPwa } from './components/InstallPwa/InstallPwa';