An open API service indexing awesome lists of open source software.

https://github.com/svagco/window

A simple macOS window with a shadow and toolbar.
https://github.com/svagco/window

javascript macos mockup svg ui

Last synced: 2 months ago
JSON representation

A simple macOS window with a shadow and toolbar.

Awesome Lists containing this project

README

          

# @svag/window

[![npm version](https://badge.fury.io/js/%40svag%2Fwindow.svg)](https://npmjs.org/package/@svag/window)

`@svag/window` is a simple macOS-style window with a shadow and toolbar.

```sh
yarn add -E @svag/window
```

## Table Of Contents

- [Table Of Contents](#table-of-contents)
- [API](#api)
* [`window(options: WindowOptions): string`](#windowoptions-windowoptions-string)
* [`WindowOptions`](#windowoptions)
* [without a shadow](#without-a-shadow)
- [TODO](#todo)
- [Copyright](#copyright)

## API

The package is available by importing its default function:

```js
import Window from '@svag/window'
```

### `window(`
  `options: WindowOptions,`
`): string`

Creates a complete `SVG` representing a macOS window.

window of a terminal

__`WindowOptions`__

| Name | Type | Description | Default |
| ---- | ---- | ----------- | ------- |
| __content*__ | _string_ | The content to display inside of the window. | - |
| __width*__ | _number_ | The width of the content. | - |
| __height*__ | _number_ | The height of the content. | - |
| backgroundColor | _string_ | The color of the window. | `#000000` |
| foregroundColor | _string_ | The foreground color of the container group which will hold the content. | `#FFFFFF` |
| noStretch | _boolean_ | Do not stretch the SVG when embedded as an image. This is achieved by explicitly setting width and height attributes on the `svg` element. | `false` |
| title | _string_ | An optional title for the window. | - |
| attributes | _object_ | Any additional attributes to set on the holder of the content, e.g., `font-family`. | - |
| minWidth | _number_ | The minimum width that the window should take. If the content's width is greater than this value, the height will adjust to the content. | - |
| minHeight | _number_ | The minimum height that the window should take. If the content's height is greater than this value, the height will adjust to the content. | - |
| paddingY | _number_ | The padding on the Y-axis (top and bottom). | `5` |
| paddingX | _number_ | The padding on the X-axis (left and right). | `5` |
| noShadow | _boolean_ | Disable the dropping shadow. | `false` |
| minify | _boolean_ | Remove whitespace between tags (e.g., between `>` and `<`). If there are any problems with generated SVG, this could be disabled. | `true` |

```js
import { makeElement } from '@svag/lib'
import Window from '@svag/window'

const line = makeElement('text', {
attributes: {
'font-family': 'Monaco, Courier',
'font-size': '12px',
x: 0,
y: 10,
},
content: `Last login: ${new Date().toDateString()} on ttys013`,
})
const line2 = makeElement('text', {
attributes: {
'font-family': 'Monaco, Courier',
'font-size': '12px',
x: 0,
y: 25,
},
content: 'svag-macbook:~ svag$ ',
})

const res = Window({
title: '🚞 Terminal',
width: 350,
height: 100,
noStretch: true,
content: [line, line2],
minify: false,
})
```

```svg























🚞 Terminal




















Last login: Tue Sep 11 2018 on ttys013


svag-macbook:~ svag$


```

To generate a window without a shadow, the `noShadow` option can be set. When `minify` attribute is not set to `false`, the whitespace will be removed.

```js
import { makeElement } from '@svag/lib'
import Window from '@svag/window'

const line = makeElement('text', {
name: 'text',
attributes: {
'font-family': 'Monaco, Courier',
'font-size': '12px',
x: 0,
y: 10,
},
content: `Last login: ${new Date().toDateString()} on ttys013`,
})
const line2 = makeElement('text', {
attributes: {
'font-family': 'Monaco, Courier',
'font-size': '12px',
x: 0,
y: 25,
},
content: 'svag-macbook:~ svag$ ',
})

const res = Window({
title: '🚞 Terminal',
width: 350,
height: 100,
noStretch: true,
content: [line, line2],
noShadow: true,
})
```

```svg

🚞 Terminal

Last login: Tue Sep 11 2018 on ttys013

svag-macbook:~ svag$

```

window without a shadow

## TODO

- [ ] Add cursor to the preview.

## Copyright

(c) [SVaG][1] 2018

[1]: https://svag.co