Skip to content

Commit

Permalink
fix: next-support. Export CSS separately, update Readme, check for ex…
Browse files Browse the repository at this point in the history
…istence of "window" in os()
  • Loading branch information
vayyala committed Apr 13, 2022
1 parent e534570 commit 38cf6b8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 29 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# commandbar-launcher


[![npm version](https://badge.fury.io/js/commandbar-launcher.svg)](https://badge.fury.io/js/commandbar-launcher)
![package size](https://img.shields.io/bundlephobia/min/commandbar-launcher/1.1.2)
![downloads](https://img.shields.io/npm/dm/commandbar-launcher)
![dependencies](https://img.shields.io/badge/dependencies-react-blue)

This component is a launcher to open Command Bar. It looks like a search bar and can be slotted into any react app. On click, it'll open the Command Bar.
This component is a launcher to open Command Bar. It looks like a search bar and can be slotted into any react app. On click, it'll open the Command Bar.

<p align="center">
<img align="center" src="https://user-images.githubusercontent.com/1981738/95909815-f774b680-0d53-11eb-95e7-95b5a9d576d3.png">
Expand All @@ -18,27 +17,32 @@ This component is a launcher to open Command Bar. It looks like a search bar and

## API

| Name | Type | Description | Default |
| ------------- | ------------- | ------------- | ------------- |
| text | string or HTMLElement | The element to render in the launcher | Find anything [ctrl+k] |
| style | CSSProperties | Style overrides for the launcher | {} |
| Name | Type | Description | Default |
| ----- | --------------------- | ------------------------------------- | ---------------------- |
| text | string or HTMLElement | The element to render in the launcher | Find anything [ctrl+k] |
| style | CSSProperties | Style overrides for the launcher | {} |

## Examples

Default usage:

```
import Launcher from 'commandbar-launcher';
import "commandbar-launcher/assets/index.css";
export const MyLauncher = () => {
return <Launcher />;
}
```

Example with changed styles:

```
<Launcher style={{ fontWeight: 700, textAlign: "center", background: "black", color: "white" }} />
```

Example with changed text:

```
<Launcher text={<div style={{color:'purple'}}>Click to search in this app</div>} />
```
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from "react";
import { render } from "react-dom";

import Launcher from "../../src";
import "../../assets/index.css";

export default class Demo extends Component {
render() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"css",
"es",
"lib",
"umd"
"umd",
"assets/*"
],
"scripts": {
"build": "nwb build-react-component --copy-files",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Launcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from "react";
import React from "react";
import { osControlKey } from "./os.js";
import { AiOutlineSearch } from "react-icons/ai";

Expand Down
41 changes: 22 additions & 19 deletions src/components/os.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
const os = () => {
const userAgent = window.navigator.userAgent;
const platform = window.navigator.platform;
const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"];
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
const iosPlatforms = ["iPhone", "iPad", "iPod"];
if (typeof window !== "undefined") {
// check window for SSR
const userAgent = window.navigator.userAgent;
const platform = window.navigator.platform;
const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"];
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
const iosPlatforms = ["iPhone", "iPad", "iPod"];

// default to Mac
let os = "MAC";
// default to Mac
let os = "MAC";

if (macosPlatforms.indexOf(platform) !== -1) {
os = "MAC";
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = "IOS";
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = "WINDOWS";
} else if (/Android/.test(userAgent)) {
os = "ANDROID";
} else if (/Linux/.test(platform)) {
os = "LINUX";
}
if (macosPlatforms.indexOf(platform) !== -1) {
os = "MAC";
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = "IOS";
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = "WINDOWS";
} else if (/Android/.test(userAgent)) {
os = "ANDROID";
} else if (/Linux/.test(platform)) {
os = "LINUX";
}

return os;
return os;
}
};

export const osControlKey = () => {
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// npm run build -- --copy-files
// npm publish

import "./index.css";
import Launcher from "./components/Launcher.js";
import { osControlKey } from "./components/os.js";
export const getControlKey = osControlKey;
Expand Down

0 comments on commit 38cf6b8

Please sign in to comment.