-
Notifications
You must be signed in to change notification settings - Fork 10
Added basic README #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
bb45821
826a97b
6e34eba
3e569aa
ec23dab
265c13f
9fea8f1
f8bfd57
3beed6f
9bfcf5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,45 +6,69 @@ A Floating UI wrapper for Svelte. | |
|
||
This project is maintained by [Hugo Korte](https://github.com/Hugos68), [Skeleton Labs](https://www.skeletonlabs.co/), and the [Svelte](https://svelte.dev/) community. Based on the amazing work by [Floating UI](https://github.com/floating-ui/floating-ui). | ||
|
||
## Contributing | ||
## Installation | ||
|
||
### Developing | ||
|
||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: | ||
Install the package using your preferred package manager. | ||
|
||
```bash | ||
npm run dev | ||
|
||
# or start the server and open the app in a new browser tab | ||
npm run dev -- --open | ||
npm add @skeletonlabs/floating-ui-svelte | ||
# pnpm add @skeletonlabs/floating-ui-svelte | ||
# yarn add @skeletonlabs/floating-ui-svelte | ||
# bun add @skeletonlabs/floating-ui-svelte | ||
``` | ||
|
||
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app. | ||
|
||
### Building | ||
## Usage | ||
|
||
To build your library: | ||
Import the desired hook or component from floating-ui-svelte, for example: | ||
|
||
```bash | ||
npm run package | ||
``` | ||
```js | ||
import { useFloating, type UseFloatingOptions } from '@skeletonlabs/floating-ui-svelte'; | ||
|
||
To create a production version of your showcase app: | ||
const options: UseFloatingOptions = { ... }; | ||
|
||
```bash | ||
npm run build | ||
const floating = useFloating(options); | ||
endigo9740 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
You can preview the production build with `npm run preview`. | ||
|
||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. | ||
## API | ||
|
||
### Publishing | ||
### `useFloating` | ||
|
||
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)). | ||
The `useFloating` hook takes care of positioning your floating UI elements (tooltips, popovers, etc.) relative to another element. | ||
It automatically calculates the best placement and updates it as needed, giving you properties to access the position and styles. | ||
|
||
To publish your library to [npm](https://www.npmjs.com): | ||
#### Import | ||
|
||
```bash | ||
npm publish | ||
```js | ||
import { useFloating } from '@skeletonlabs/floating-ui-svelte'; | ||
``` | ||
|
||
#### Options | ||
Hugos68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
| Property | Description | Type | Default Value | | ||
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------- | | ||
| open | Represents the open/close state of the floating element. | boolean | true | | ||
| onOpenChange | Event handler that can be invoked whenever the open state changes. | (open: boolean, event?: Event, reason?: OpenChangeReason) => void | - | | ||
| placement | Where to place the floating element relative to its reference element. | Placement | 'bottom' | | ||
| strategy | The type of CSS position property to use. | Strategy | 'absolute' | | ||
| middleware | These are plain objects that modify the positioning coordinates in some fashion, or provide useful data for the consumer to use. | Array<Middleware \| undefined \| null \| false> | undefined | | ||
| transform | Whether to use `transform` instead of `top` and `left` styles to position the floating element (`floatingStyles`). | boolean | true | | ||
| elements | The reference and floating elements. | FloatingElements | - | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO the name of the variable speaks for itself, on top of the example above. Though I'll leave this open for others to comment about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer |
||
| whileElementsMounted | Callback to handle mounting/unmounting of the elements. | (reference: ReferenceElement, floating: FloatingElement, update: () => void) => () => void | - | | ||
|
||
#### Return | ||
|
||
| Property | Description | Type | | ||
| -------------- | ---------------------------------------------------------------------------------------------- | --------------- | | ||
| x | The x-coord of the floating element. | number | | ||
| y | The y-coord of the floating element. | number | | ||
| placement | The stateful placement, which can be different from the initial `placement` passed as options. | Placement | | ||
| strategy | The stateful strategy, which can be different from the initial `strategy` passed as options. | Strategy | | ||
| middlewareData | Additional data from middleware. | MiddlewareData | | ||
| isPositioned | The boolean that let you know if the floating element has been positioned. | boolean | | ||
| floatingStyles | CSS styles to apply to the floating element to position it. | string | | ||
| update | The function to update floating position manually. | () => void | | ||
| context | Context object containing internal logic to alter the behavior of the floating element. | FloatingContext | | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
Uh oh!
There was an error while loading. Please reload this page.