GithubHelp home page GithubHelp logo

shopify / buy-button-js Goto Github PK

View Code? Open in Web Editor NEW
240.0 457.0 114.0 3.01 MB

BuyButton.js is a highly customizable UI library for adding ecommerce functionality to any website.

Home Page: http://shopify.github.io/buy-button-js/

License: MIT License

JavaScript 90.48% CSS 9.40% HTML 0.12%
javascript ecommece

buy-button-js's Introduction

BuyButton.js

BuyButton.js on NPM Travis

BuyButton.js is a highly customizable UI library for adding ecommerce functionality to any website. It allows you to create interactive UI components such as product listings and shopping carts with minimal configuration, while allowing you to easily customize the appearance and behaviour of the components. It uses the JS Buy SDK to connect to your Shopify store, giving you access to your products and collections.

To get started, take a look at the documentation. For questions, suggestions and feeback, please create an issue.

Development

yarn
cp index.example.html index.html
  • Add your API key and shop domain to index.html
  • Set a product ID in index.html
yarn run start

Will watch for changes, compile src/ to tmp/ using babel & browserify, and run a server on port 8080.

Testing

yarn run test

will run full test suite locally

yarn run test-dev

Will watch for changes and run test suite.

Documentation

To run docs locally, install jekyll:

gem install jekyll
yarn run docs

Doc server will run at http://localhost:4000/buy-button-js/ Docs source files are located in /docs. Docs are automatically deployed to gh-pages from master.

buy-button-js's People

Contributors

alxgmpr avatar cursedcoder avatar dependabot[bot] avatar gabrielmaldi avatar harisaurus avatar jameskim08 avatar jamiemtdwyer avatar jmignac avatar lreeves avatar lyninx avatar marius92mc avatar melissaluu avatar michenly avatar minasmart avatar philibertdugas avatar rebeccajfriedman avatar saulecabrera avatar sbfaulkner avatar spareshade avatar stefanslehta avatar suusan2go avatar tanema avatar tessalt avatar tombennet 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  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

buy-button-js's Issues

Column sizes

Left column size should be aligned with secondary column 266-340px
Right column size should be aligned with primary column 498-690px

IE9 styles

  • button styles when disabled
  • adapter footer

Product Modal

product embed sprint

  • stylesheets
  • update selected variant in dropdown
  • images
  • nonexistent variant
  • events
  • no variants
  • focus/hover states
  • event handlers
  • disabled selections

API Stuff

  • media queries?

Analytics

The ui library should use the new version of trekkie and as per @drdee recommendations we should be doing this early.

This could probably use more discussion but I believe trekkie should still be in the UI lib because it serves the same flow as previous versions when the buy buttons are built using the builder. However I think it might be good to have a conversation about adding it to the js-buy-sdk but disabled by default and give the developer an option to use Shopify statistics.

cc @richgilbank

Tricorder Brief

feedback

  • revisit getters
  • naming things (node, wrapper, props, etc)

quantityIncrement/Decrement options do not apply

I am trying to apply styles to the increment buttons on line items in the cart. I pass the options to the line item options. I have also tried passing the options to the cart but both do not work.

Styling requirements

  • Centre single vertical product embed
  • Increase outer body margin for additional space

cart & collections sprint

Cart

  • initialize cart on product initialization
  • initialize cart by by itself
  • customize cart settings and styles
  • add variant to cart
  • increase/decrease quantity of line item
  • remove line item from cart
  • check out
  • show/hide cart
  • product button defaults to cart, can be customized to go straight to checkout
  • ensure cart appended at end of dom
  • host styles
  • empty state

Collections

  • createComponent('collection')
  • create multiple products not in collection

Style

  • collection styles
  • cart/line item styles
  • animate cart things
  • clean up css
  • support media queries
  • scroll list items
  • conditional classes

misc other

  • initialization interface (wrt shopifybuy etc)
  • confirm entry node initialization works as expected
  • clean up appendStyleTag
  • render product faster (don't wait for cart)
  • prevent multiple instances of ui
  • show total line items in cart toggle
  • separate stylesheets by modules
  • variant with no image
  • mobile testing
  • quantity field on product
  • make sure scroll bars don't happen
  • watch browser resize
  • close cart on background click
  • normalize class name keys (ex productTitle, cartTitle)

Template options

String templates

 templates: {
        title: '<h4>{{data.title}}</h4>',
        button: '<button data-event="click.addVariantToCart">Special Add To Cart</button>'
      },

Pros

  • familiar to most developers
  • just strings, so don't need to be wrapped in functions

Cons

  • just strings, so tricky to build DOM with:
    • binding events via manual DOM querying
    • or basically re-implement ember or backbone's views
    • re-rendering the DOM after updates are made is manual
    • need to compile templates at runtime, handlebars is kinda big

Hyperscript "templates"

templates: {
    'title': (data) => {
      return h('h2', data.name)
    },
    'button': (data, events) => {
      return h('button', {
        onclick: (e) => {
          events.addVariantToCart()
        }
      }, 'Special add to cart')
    }
  },

Pros

  • efficient and predictable re-rendering after updates via virtual dom or morphdom (8kb)
  • simple event binding via attributes (since hyperscript creates actual DOM, not strings)
  • prevent DOM querying, more easily expose nodes through API
  • no compilation

Cons

  • much less intuitive than string templates
  • emerging standard, vs handlebars which has been around for years

QA plan / tests

  • chrome
  • firefox
  • IE 9
  • IE 10
  • IE 11
  • Edge
  • iOS > 9
  • iOS >= 7
  • Android 4.3+
  • Android <= 4.3 >= 4.0

ShopifyBuy.UI

  • create a component
  • customize a component

Product embed

  • open modal
  • add to Cart
  • open checkout
  • open product page
  • change quantity
  • change variant
  • click product instead of button
  • customize cart
  • customize toggle
  • customize modal

Collection embed

  • named collection
  • set of random products
  • customize product
  • all product functionality

Cart

  • remove item from cart
  • increment quantity of item
  • set quantity of item
  • calculate price
  • scroll long list
  • close cart clicking bg or x
  • display 'empty cart' message
  • open checkout

Cart toggle

  • open cart
  • only show when cart has items
  • reflect count of items in cart * quantity

Modal

  • close modal clicking bg or x
  • scroll overflow content
  • all product functionality

Cart and toggle button styles not being applied.

I apply the following config

{  
   toggle:{  
      styles:{  
         toggle:{  
            "background-color":"#abc123",
             color: '#abc123'
         }
      }
   },
   cart:{  
      styles:{  
         button:{  
            "background-color":"#abc123",
             color: '#abc123'
         }
      }
   }
}

and none of these styles are applied.

potential performance/filesize optimizations

  • share common styles in style object
  • replace lodash.merge with smaller deep merge util (that supports copying getters)
  • ship un-polyfilled version?

bundles by file size, post uglification

bundle size
babel-runtime 60kb
shopifyBuy 43kb
polyfills (other than babel) 42kb
lodash 36kb
styles 23kb
hogan 14kb
morphdom 9kb

Actual application code: 36kb

browser issues

  • vertical scrollbars on horizontal product in IE9
  • horizontal scrollbar on cart toggle in IE9
  • not taking up full width in IE
  • [Firefox]: quantity button misaligned
  • [Firefox] quantity input not working

backlog

  • bugsnag?
  • build buy-button-storefront
  • fix adapter styles
  • tricorder
  • collection pagination
  • collection sorting
  • font support
  • invalid id handling
  • manage default styles
  • move adapter
  • integration testing
  • only re-render image if url is different? (excluding params?)
  • pass legacy cart config to product
  • better error handling for wrong IDs
  • rethink modal template: move gross stuff to adapter
  • customize svg colour
  • replace lodash.merge
  • label in option value
  • support multiple layouts for product
  • collection rendering performance
  • adapt styles to new design
  • move modal dom re-arrangement to adapter
  • quantity contents
  • link to product page
  • IE Testing
  • prevent jank when changing images
  • how to deal with passing styles from product to productModal
  • overflow:hidden before height set
  • product scroll bar
  • handle unavailable products
  • animate things
  • clicking image action
  • update ALL configs
  • really really high z-indices
  • modals without images
  • host click closes cart
  • handle unexpected inputs
  • modal desktop styles
  • styles cleanup
  • responsive collections
  • lifecycle hooks vs. subclassing (don't wrap methods)
  • object assign vs deep merge
  • child element abstraction?
  • getters leaky state
  • images: event handlers need to be attached before src
  • specific variant
  • sizing of items in collection grid
  • cart height
  • resize on updateConfig
  • multiple script tags
  • location of embeds vs script tags
  • async script tags
  • actual cart icon
  • file sizes
  • quantity update?
  • second modal click
  • incognito carts#undefined not found

Adapter todo transforms

  • apiKey for legacy buy buttons to use the js-buy-sdk
  • product component
  • collection component
  • cart component
  • data-display_size
  • data-has_image
  • data-redirect_to
  • data-product_modal
  • data-buy_button_text
  • data-button_background_color
  • data-button_text_color
  • data-background_color
  • data-show_product_price
  • data-show_product_title
  • data-buy_button_out_of_stock_text
  • data-buy_button_product_unavailable_text
  • data-product_title_color
  • data-checkout_button_text
  • data-text_color
  • data-accent_color
  • data-cart_title
  • data-cart_total_text
  • data-discount_notice_text
  • data-sticky
  • data-empty_cart_text
  • data-next_page_button_text

fix installation

should be resolved once we can run build in prepublish when the module is on NPM

Height calculation is off without image, title, price.

The embed is showing too small with scroll bars when the image, title and price are all hidden.

image

Here is the code I was using exactly incase the large options object is causing side effects

    ui.createComponent('product', {
      handle: 'product-handle',
      node: elem,
      options: {
   "product":{
      "text":{
         "button":"Buy It Now!"
      },
      "contents":{
         "img":false,
         "price":false,
         "title":false
      },
      "styles":{
         "button":{
            "background-color":"#8db461",
            "color":"#ffffff"
         },
         "variantTitle":{},
         "title":{
            "color":"#000000"
         },
         "price":{},
         "wrapper":{
            "width":"230px"
         }
      }
   },
   "productSet":{
      "styles":{
         "product":{},
         "wrapper":{}
      },
      "products":{}
   },
   "modalProduct":{
      "styles":{
         "button":{},
         "wrapper":{}
      }
   }
}
    });

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.