0.0.364 • Published 10 months ago

@appdirect/sfb-theme-components v0.0.364

Weekly downloads
62
License
UNLICENSED
Repository
github
Last release
10 months ago

sfb-theme-components

Components used by the storefront builder to build themes.

Installation

  • Install dependencies with npm install
    • After upgrading to Node 16, you have to do npm install --legacy-peer-deps instead

Local development using a Marketplace

  • Start server with npm start
  • You can use resource override for the js and css:
    • From: https://engage19billing.test.devappdirect.me/sfb-theme-components@0/* to http://localhost:3444/*
    • Replace MP url of your choice

Local development using toolkit

  • Install sfb-toolkit.
  • Setup a theme project with a Plaza theme: sfb-toolkit setup.
  • Start the sfb-toolkit local server: sfb-toolkit start.
  • Start the sfb-theme-components local server to serve the bundles: npm run start
  • You can do the resource override for the js and css:
    • From: https://engage19billing.test.devappdirect.me/sfb-theme-components@0/* to http://localhost:3444/*

Storybook

To view the components, we can start the Storybook server:

  • Run npm run storybook.
  • Navigate to http://localhost:8087/.
  • On the left hand navigation bar, selecting a Component/Atom will render the component in the main section.
  • We are using Storybook Knobs to update the component's settings prop in Storybook.

Creating custom components for your theme

CSS - Naming convention

We're gonna follow modified version of: https://css-tricks.com/abem-useful-adaptation-bem/

  • NO a/o/m prefixes
  • Names with more then one term should use camelCase convention instead of -
  • Modifiers are using -- (double dash) and are connected with the name

Examples:

// just an element, nothing to see
<div class="blockName_elementName"></div>
// with a modifier
<div class="blockName_elementName blockName_elementName--modifier"></div>

For more detailed examples please take a look in section CSS - Naming Tool

Component's structure

There are two folders for components:

  • atoms/ which should include very basic, easily re-usable across different themes and styling components like Image, Button, Header, etc.
  • components/ should contain components that are more specific for a theme, most of the time are including one or more atom components

Doing Responsive

Proptypes and functional components are inforced

CSS - Naming Tool

There has been implemented namingTool to help out follow above CSS naming structure:

Every component should contain:

import { createNamespace } from './tools/namingTools';

const n = createNamespace('MyComponentName');

Simple usage:

<div {...n(element[, [modifiers]]).props}></div>
  • modifier is optional and can be either string or array of strings

Examples

Element with modifier:
<div {...n('elementName', 'myModifier').props}></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--myModifier">
</div> 
Element with list of modifiers:
<div {...n('elementName', ['myModifier1', 'myModifier2']).props}></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--myModifier1 
           myComponentName_elementName--myModifier2">
</div> 
Element with testId: .withTestId()
<div {...n('elementName').withTestId().props}></div> 
// translates to
<div class="myComponentName_elementName" data-testid="myComponentName:elementName"></div> 
Element with custom testId: .withTestId(*)
<div {...n('elementName').withTestId('myTestId').props}></div> 
// translates to
<div class="myComponentName_elementName" data-testid="myComponentName:myTestId"></div> 
Element with testId only: .withTestId()
<div {...n().withTestId('myTestId').props}></div> 
// translates to
<div data-testid="myComponentName:myTestId"></div> 
Element with extra class .withClass(*)
<div {...n('elementName').withClass('myExtraClass').props}></div> 
// translates to
<div class="myComponentName_elementName myExtraClass"></div> 
Element with extra classes .withClass(*)
<div {...n('elementName').withClass(['myExtraClass1', 'myExtraClass2']).props}></div> 
// or
<div {...n('elementName').withClass('myExtraClass1').withClass('myExtraClass2').props}></div> 
// translates to
<div class="myComponentName_elementName myExtraClass1 myExtraClass2"></div> 

namingTool and it's functions .withClass(), .withTestId() are chainable which means you can work on the results of each function until the .props will be called.

Complex example
<div 
     {...n('elementName', ['modifier1', modifier2'])
         .withClass(['myExtraClass1', 'myExtraClass2'])
         .withClass('testClass')
         .withTestId()
         .props
     }></div> 
// translates to
<div 
    class="myComponentName_elementName 
           myComponentName_elementName--modifier1
           myComponentName_elementName--modifier2
           myExtraClass1 
           myExtraClass2
           testClass"
    data-testid="myComponentName:elementName "
></div> 

Jest - Testing & Debugging

There are five launch configurations defined that can be used to test and debug:

  • Jest run all test suites - this configuration will go through all test suites and all test cases defined in the project.
  • Jest run selected test suite - this configuration will run all test cases found in the file (test suite) that is currently selected in your workspace.
  • Jest run all tests matching selected text - this configuration will run all test cases that will match the text selected/highlighted in your workspace (multiple tests can match depending on the selected text)
  • Jest run all test suites matching prompted input - this configuration will run all test suites that contain/match the text provided in the input box that will show up once the configuration is run (multiple test suites can match)
  • Jest run all tests matching prompted input - this configuration will run all test cases that contain/match the text provided in the input box that will show up once the configuration is run (multiple test cases can match)

NOTE: Breakpoints should work correctly in VS Code when using the above configurations.

0.0.362

10 months ago

0.0.364

10 months ago

0.0.361

11 months ago

0.0.360

11 months ago

0.0.353

1 year ago

0.0.352

1 year ago

0.0.335

2 years ago

0.0.334

2 years ago

0.0.339

2 years ago

0.0.338

2 years ago

0.0.340

2 years ago

0.0.344

2 years ago

0.0.342

2 years ago

0.0.329

2 years ago

0.0.331

2 years ago

0.0.326

2 years ago

0.0.325

2 years ago

0.0.315

2 years ago

0.0.314

2 years ago

0.0.318

2 years ago

0.0.317

2 years ago

0.0.321

2 years ago

0.0.303

2 years ago

0.0.302

2 years ago

0.0.306

2 years ago

0.0.294

3 years ago

0.0.293

3 years ago

0.0.292

3 years ago

0.0.278

3 years ago

0.0.284

3 years ago

0.0.282

3 years ago

0.0.289

3 years ago

0.0.288

3 years ago

0.0.286

3 years ago

0.0.280

3 years ago

0.0.290

3 years ago

0.0.274

3 years ago

0.0.272

3 years ago

0.0.271

3 years ago

0.0.268

3 years ago

0.0.266

3 years ago

0.0.265

3 years ago

0.0.264

3 years ago

0.0.262

3 years ago

0.0.261

3 years ago

0.0.259

3 years ago

0.0.258

3 years ago

0.0.257

3 years ago

0.0.252

3 years ago

0.0.254

3 years ago

0.0.260

3 years ago

0.0.237

4 years ago

0.0.245

3 years ago

0.0.244

3 years ago

0.0.243

3 years ago

0.0.242

3 years ago

0.0.236

4 years ago

0.0.235

4 years ago

0.0.228

4 years ago

0.0.224

4 years ago

0.0.221

4 years ago

0.0.220

4 years ago

0.0.214

4 years ago

0.0.211

4 years ago

0.0.210

4 years ago

0.0.208

4 years ago

0.0.207

4 years ago

0.0.206

4 years ago

0.0.203

4 years ago

0.0.202

4 years ago

0.0.201

4 years ago

0.0.200

4 years ago

0.0.192

4 years ago

0.0.185

4 years ago

0.0.184

4 years ago

0.0.182

4 years ago

0.0.180

4 years ago

0.0.179

4 years ago

0.0.175

4 years ago

0.0.173

4 years ago

0.0.167

4 years ago

0.0.6

6 years ago

0.0.4

6 years ago