Giter VIP home page Giter VIP logo

react-tiny-fab's Introduction

React Tiny FAB

A tiny (~700 byte gzip) WAI-ARIA compliant Floating Action Button for React

react-tiny-fab v3 now relies on React version 16.8 and up because it is implemented using React Hooks

Want to use a Floating Action Button without having to import the whole Material Design Components library? Weighing in at only around 671 bytes gzipped, React Tiny FAB is a great solution. It is a lightweight, fast, and flexible component.

React Tiny FAB

Docs

Please visit here for docs: https://dericcain.github.io/react-tiny-fab/

Issues

If you find an issue, head over to the Issues section and let me know about it. If you want to be super cool, you can submit a PR that fixes the issue.

License (MIT)

Check it out here.

react-tiny-fab's People

Contributors

ae-ndoak avatar ajcpwnz avatar alainpilon avatar askamist avatar benbristow avatar d-ivashchuk avatar dependabot[bot] avatar dericcain avatar dovy avatar dpills avatar ettingshausen avatar hasheddan avatar hds-inc avatar impressivewebs avatar kdavis-ssi avatar nomoreviolence avatar osmarpetry avatar shanhuiyang avatar siqueira-ec avatar sircodesalittle avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-tiny-fab's Issues

Allow custom main button

Hi !

I currently use this awesome component with a "burger menu" icon, which does not look nice with the rotation. It ends up like this :
image

I would love to be able to replace the main button with another one (like this one 🀩 ).
If I use this as the icon for the Fab component, it rotates (which is ugly here) and cannot fire the menu opening/close on clic, and cannot be notified on menu opening.

This would imply that we could also :

  • achieve the behavior asked in #53 by @ulsha, so that the custom button toggles the menu opening
  • set a "menu opened" callback, so that we can trigger any custom button state
  • disable icon rotation

What do you think of this?

Action Menu remains open when menu item is clicked?

I just updated from v3.5.0 to v4.0.2 and noticed the action menu remains open when a menu item is clicked?

Is this by design?

The demo on the documentation page closes as expected, which is throwing me off.

On React v17.0.2

Did you have problems with a "Module parse failed" error?

Hi! I use webpacker for a work with ES6.
And it was okay.
But your package doesn't work.
If you had this issue, please, talk me about solution =)

./node_modules/react-tiny-fab/dist/fab.esm.js
Module parse failed: Unexpected token (37:1076)
You may need an appropriate loader to handle this file type.

Add speed animation control

Hi Deric, nice component so thank a lot to share it!
It would be nice if you will add a prop to setup the animation speed of the appearing actions πŸ˜‡

Define which way the menu is opened

Hello,
I'd like to use a react-tiny-fab in every Card component in the dashboard I'm creating.
It would be amazing to be free to position the react-tiny-fab in a position relative to its parent component.
It would be amazing to be free to define which way it expands.

For the moment I have positioned it this way but it's not clean at all.

 <Fab
        icon={<Settings />}
        event="hover"
        key={uuid.v4()}
        alwaysShowTitle={false}
        position={({ zIndex: 0, ...position })}
      >

Where position is calculated

const offsets = { top: -90, left: -90 } // this is the distance from the bottom-left corner of the Card
const position = { top: top + height + offsets.top, left: left + width + offsets.left } // this is evaluated in something like {top: 200, left:500 }

I also had to pass the zIndex parameter through the position prop because I haven't found a cleaner way to customize the component.

I haven't found any beautiful alternative around and this is the reason why I'd like to be able to customize a little bit more.

Thank you

Use the FAB without menu

Thanks for this good widget.
Sometimes I just have one action to add into the FAB.
Then I do not want to expand the menu while user click the FAB; instead I want directly take the action while user click the FAB.
It seems like I have no way to do that.
Could you please support that. I think we can just add an onClick property so that FAB can take the onClick action directly.

the target undefined

Hi
when I set onClick function on any component between component I can't trigger the target

function handleClick(e){
     console.log(e)
}

return(
<Fab>
<someComponentOrAction onClick={handleClick} />
</Fab>
)

results in console: undefined

how is that possible?

Compatibility issue on Edge

Found following error on Edge

SCRIPT1028: SCRIPT1028: Expected identifier, string or number
fab.esm.js (84,1)

edgeerror

onMouseLeave cancels out onClick toggle

Current behaviour:
Even though logic exists to keep TinyFab visible when clicked, the class was being removed onMouseLeave.
Expected behaviour:
TinyFab stays visible when clicked until clicked again to allow closing.

HowTo: Disable react-tiny-fab only supports up to 6 action buttons

I understand only 6 buttons max are supported but I needed 8. I've added 8 with css modification; works great and a super thank you for such tool.

Is there a way to disable this console log warning:

react-tiny-fab only supports up to 6 action buttons

PS: I wish not to fork.

Thanks.

Fab cannot float correctly while the window is narrow

For example on the mobile browser the FAB is stick to the bottom of the layout but not float.
If this is bug? In desktop browser the FAB is works very well. I think this issue is easy to reproduce.

It looks like I am doing something wrong but I don't know what's is wrong...
The example FAB looks good on mobile browser.

How to show label by default?

How can I show the label by default without hovering? It will be useful in mobile views because there is no hover in mobile.

Example tap behavior stops working

This might not be an issue with the component, but on the example I identified buggy behavior.

If I tap the button to open the menu with the two options (= and +) and I tap =, after I tap the OK button on the Alert that it spawns and the menu closes, I am no longer able to tap the button to re-open the menu, without first de-focusing it.

I recorded a video here:
https://imgur.com/a/fITbFt3

It's a bit hard to see because I'm tapping my touch screen, but hopefully the description above explains it.

Get example working in "example" folder

In version previous to v4, there was an example in the example folder that would run when running npm run start. Since the update to v4, this no longer works. All of the code for the examples is here: https://github.com/dericgw/react-tiny-fab/blob/master/example/index.html

Ideally, we would want to run npm run start:example and the example would be served in the browser. I am not overly concerned with live reload since there aren't too many changes made to this library. I don't want to use Create React App because it is a bit too much for just displaying one page. I am okay with using something like Parcel, or even getting it working like it is within an HTML page.

Allow className props

Is there a reason to why we can't do that? It would be handy for people who don't use React styles.

Title text not showing when using react-router-dom Link

Love the library. Thanks.

So when I surround the Action component with Link from react-router-dom, the title text does not show. So I tried adding an onClick handler instead but its also not working.

<Fab
    mainButtonStyles={{ backgroundColor: '#26978A', }}
    icon={<AddIcon />}
    alwaysShowTitle={true}
    >
    <Link
        to={{
            pathname: '/AddEvent',
            state: id,
        }}
        >
        <Action text="Add Event" style={{ backgroundColor: '#666', }}>
            <CalendarTodayOutlinedIcon />
        </Action>
    </Link>
</Fab>

Screen Shot 2021-04-06 at 5 53 07 PM

Is there an easy fix so that the text title shows? It's not a big issue but it would be nice to show the text to the User.
Here's a codeandsandbox:

https://codesandbox.io/s/dark-hooks-pzxyc?file=/src/App.js

Clicking on iOS device in Safari and Chrome not working

Hi,

I've been trying to test tiny-fab on an iOS device. And only the first click sometimes works on Safari, but then no click events are fired. I see a similar issue in Chrome on iPhone X as well.

Has anyone run into this issue? Also, what other information should I provide to dig into it more?

Make Floating Action Button WAI-ARIA compliant

I would be nice to have the component accessible for those that use screen readers and such. I am not positive what all goes into making this happen so I am going to start researching it. However, this should be some pretty low hanging fruit.

Home page update

https://dericgw.github.io/react-tiny-fab/#/

This part need to change.

Usage
There are two components available for import - Fab and Action. You import them like this:

1
import { Fab, Action } from 'react-tiny-fab';
2

import 'react-tiny-fab/styles.css';

to

import 'react-tiny-fab/dist/styles.css';

The description between github README and homepage is different.

The github document you wrote is correct.

Open FAB horizontally instead of vertical

I am new to this library but I guess the opening direction is fixed(vertical).Is there option to open it horizontally(Like right to left or left to right)? or any suggestion how to do that with css changes?

Transform dist/ from es6 to es5

/****  React Tiny FAB - Deric Cain<[email protected]>  *****/
import React, { useState } from 'react';

function _extends() {
  _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];

      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }

    return target;
  };

  return _extends.apply(this, arguments);
}

const AB=a=>React.createElement("button",_extends({type:"button"},a,{className:"rtf--ab"}),a.children);const MB=a=>React.createElement("button",_extends({type:"button",className:"rtf--mb"},a),a.children);const defaultPosition={bottom:24,right:24},Fab=({event:d="hover",position:e=defaultPosition,alwaysShowTitle:f=!1,children:a,icon:b,mainButtonStyles:c})=>{const[g,h]=useState(!1),i=()=>h(!0),j=()=>h(!1),k=a=>{h(!1),setTimeout(()=>{a();},1);};return React.createElement("ul",{onMouseEnter:()=>"hover"===d&&i(),onMouseLeave:()=>"hover"===d&&j(),className:`rtf ${g?"open":"closed"}`,style:e},React.createElement("li",{className:"rtf--mb__c"},React.createElement(MB,{onClick:()=>"click"===d?g?j():i():null,style:c,role:"button","aria-label":"Floating menu",tabIndex:"0"},b),React.createElement("ul",null,(()=>{6<React.Children.count(a)&&console.warn("react-tiny-fab only supports up to 6 action buttons");const b=f||!g;return React.Children.map(a,(a,c)=>a&&React.createElement("li",{className:`rtf--ab__c ${"top"in e?"top":""}`},React.cloneElement(a,{"data-testid":`action-button-${c}`,"aria-label":a.props.text||`Menu button ${c+1}`,"aria-hidden":b,...a.props,onClick:()=>k(a.props.onClick)}),a.props.text&&React.createElement("span",{className:`${"right"in e?"right":""} ${f?"always-show":""}`,"aria-hidden":b},a.props.text)))})())))};

export { AB as Action, Fab, MB };

the dist code is not translate to es5...

Unable to conditionally render Actions

When attempting to conditionally render Actions such as in the following example the below type error is received.

repro: https://codesandbox.io/s/react-tiny-fab-conditional-render-1qlc3

Uncaught TypeError: Cannot read property 'props' of null
function App() {
  const [vis, setVis] = useState(true);
  return (
    <>
      <button onClick={() => setVis(!vis)}>{vis ? "remove" : "add"}</button>
      <Fab alwaysShowTitle={true} icon="ℹ️">
        <Action text="Fire" onClick={() => console.log("fire")}>
          πŸ”₯
        </Action>
        {vis && (
          <Action text="Up" onClick={() => console.log("Up")}>
            πŸ‘
          </Action>
        )}
        <Action text="Down" onClick={() => console.log("Down")}>
          πŸ‘Ž
        </Action>
      </Fab>
    </>
  );
}

Hidding the Menu after clicking on one item

Hello, Can I trigger the mouseleave event after I click on one of the menu items. Currently, I am opening a dialog after clicking on the first item in the menu but the state of the FAB not changing from open true to open false. I tried to trigger the mouseleave (mouseout) events from the code but no success. My goal is just hide the menu after clicking on any of the items in the menu

Missing type definition

Issue

#22 is pushed type definition into this repo, but npm published module has not d.ts file.

Reason

The reason is that the package.json types field specifies src/index.d.ts, but the src directory is not included in publish.

Suggestion

I think it can be solve by either.

  • Include src directory to publish with files field in package.json.
  • Deploy index.d.ts to dist directory.

What do you think?

SCRIPT1028: Expected identifier, string or number

on Microsoft Edge the error 'SCRIPT1028: SCRIPT1028: Expected identifier, string or number' appears in the console and a blank page is rendered when just adding import { Fab, Action } from 'react-tiny-fab'; to .jsx

using Create-react-app with the latest react-scripts...here is the excerpt from package.json..

"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0",
"react-tiny-fab": "^3.2.0",

Add prop so that FAB can be open/closed externally

Hello,
I'm a fan of react-tiny-fab - I like the simplicity of the implementation and design.
One thing I am missing, however, is a prop so that the component can be toggled/untoggled externally - for example, if a new process/job arrives the FAB should be toggled to display its progress. The user can then untoggle it automatically again.

It could be as simple as

 <Fab
        icon="+"
        event='click'
        toggled="true" /* or false */
>

I need type definition

I use typescript react,
But, there is no any type definition
can you support for typescript react users?

FAB can't open after been closed

Hi,
once the FAB is been closed it won't open again.

Step to reproduce (this only happens on mobile and event='hover')

  1. open fab
  2. press one of the actions, at this point fab is closed
  3. try to open fab again...nothing happen

this bug is unlocked by typing on the background

I think this issue is related to #75 , but he doesn't mention is only about mobile.

You can test it in your page too

Support more than 6 buttons

I'm creating a tool bar with your library and I added one more button over 6 and the UI breaks. I understand 6 is only supported. Is it possible support than six?

Need an Improvement

It will be much better if, it can always show the children of the fab.
The event 'hover' or 'click' doesn't meet this requirement. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.