Skip to content

Commit

Permalink
Merge pull request #1 from IBM/feature/initial-code-checkin
Browse files Browse the repository at this point in the history
add sample components, webpack conf, package.json
  • Loading branch information
bdjos1 authored Oct 22, 2021
2 parents be957eb + 348f599 commit e7fb668
Show file tree
Hide file tree
Showing 28 changed files with 842 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/env", "@babel/preset-react"]
}
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Defines the Output Bundle Path for the "npm run dev" target.
# It is recommended to point it directly to the SPM jscript folder.
# For example: %SPM_ROOT_PATH%/webclient/WebContent/CDEJ/jscript/SPMUIComponents
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/**
dist/**
43 changes: 43 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"parser": "babel-eslint",
"plugins": [
"react",
"jsx-a11y",
"react-hooks",
"notice",
"prettier"
],
"env": {
"browser": true,
"jest": true
},
"rules": {
"react-hooks/rules-of-hooks": "error",
"react/jsx-fragments": [
0
],
"react/forbid-prop-types": [
2,
{
"forbid": [
"any"
]
}
],
"react/jsx-props-no-spreading": 0,
"arrow-parens": 0,
"react/jsx-filename-extension": 0,
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true,
"peerDependencies": true
}
]
}
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Dependency directories
node_modules/
dist/

# storybook
storybook-static/
15 changes: 15 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules

.publish

.editorconfig
.eslintignore
.eslintrc
.travis.yml

gulpfile.js
index.js
webpack.config.js

CONTRIBUTING.md
README.md
10 changes: 10 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials"
]
}
11 changes: 11 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../src/scss/index.scss';

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}
17 changes: 17 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const path = require('path');
const glob = require('glob');
const custom = require('../webpack.config.js');

module.exports = async ({ config, mode }) => {
config.module.rules.push({
test: /\.scss$/,
loaders: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});

return {
...config,
module: { ...config.module },
devServer: custom.devServer,
};
};
60 changes: 60 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@


/* eslint-disable no-console */
const path = require('path');
const gulp = require('gulp');
const shell = require('shelljs');

// Load env vars from the .env file.
require('dotenv').config();

/*
* This task generates a development bundle to the specified output folder.
* Also the bundle is generated, it watches the projects folder for changes.
* Any changes in the project kicks off a Delta bundle generator only for
* the file that was changed.
*
* - The output folder is defined in the .env file
* through the variable: DEV_BUNDLE_OUTPUT
* If not variable is defined, it defaults to /dist
*
* - The development bundle uses the source maps strategy "eval-source-map"
* It is the slowest build option but it enables the developer to debug
* on the browser exactly the same code he sees in the code editor
* before it is transpiled by Babel.
*/

gulp.task('dev:spm', () => {
const output =
process.env.DEV_BUNDLE_OUTPUT ||
path.resolve(__dirname, '/dist');
if (!process.env.DEV_BUNDLE_OUTPUT) {
shell.echo(
`\n[WARNING] Env var DEV_BUNDLE_OUTPUT not defined in the .env file.
Using Default Output: ${output}`
);
}

shell.echo(`\n[INFO] Generating the dev bundle to path: ${output}
[INFO] Any changes to the files will automatically trigger a new bundle generation.`);

shell.exec(
`webpack --mode=development --devtool=eval-source-map\
--output-path=${output} --watch=true --hide-modules=true\
--build-delimiter="\n\n[INFO] Bundle Generated into ${output} \n[INFO] Watching for file changes."`,
{ fatal: true }
);
});

gulp.task('prod:spm', (done) => {
const output = path.resolve(__dirname, '/dist');

shell.echo(`\n[INFO] Generating the dev bundle to path: ${output}.`);

shell.exec(
`webpack --mode production`,
{ fatal: true, silent: true }
);
done();
});

74 changes: 74 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "custom-carbon-addons",
"version": "0.0.1",
"description": "Enable customers to develop the content within the package, Carbon Components, and GraphQl using the apollo client. It also enables customer to build and deploy this new package.",
"main": "index.js",
"husky": {
"hooks": {
"pre-commit": "npm run lint"
}
},
"scripts": {
"build": "gulp prod:spm",
"dev": "gulp dev:spm",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "./node_modules/.bin/eslint ./src",
"start": "webpack-dev-server --mode development",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"author": "Tom Delahunty",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"@storybook/addon-actions": "^6.3.8",
"@storybook/addon-essentials": "^6.3.8",
"@storybook/addon-links": "^6.3.8",
"@storybook/react": "^6.3.8",
"babel-loader": "^8.0.2",
"babel-eslint": "^10.1.0",
"css-loader": "^1.0.0",
"dotenv": "^8.2.0",
"dotenv-webpack": "^3.0.0",
"eslint": "^7.11.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-notice": "^0.9.10",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.4",
"eslint-plugin-react-hooks": "^4.1.2",
"gulp": "^4.0.2",
"gulp-cli": "^2.3.0",
"husky": "^4.3.0",
"node-sass": "^4.14.1",
"sass-loader": "^10.0.3",
"shelljs": "^0.8.4",
"style-loader": "^0.23.0",
"webpack": "4.42.1",
"webpack-cli": "3.3.11",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"@carbon/grid": "^10.20.0",
"@carbon/icon-helpers": "^10.13.0",
"@carbon/icons": "^10.25.0",
"@carbon/icons-react": "^10.25.0",
"@carbon/layout": "^10.17.0",
"@carbon/pictograms-react": "^11.2.0",
"@carbon/type": "^10.20.0",
"carbon-components": "10.44.0",
"carbon-components-react": "7.41.0",
"carbon-icons": "^7.0.7",
"classnames": "^2.2.6",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-app-polyfill": "^1.0.6",
"regenerator-runtime": "^0.13.7",
"prop-types": "*"
}
}
22 changes: 22 additions & 0 deletions public-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Path to SPMUIComponents directory (relative to WebContent folder).
const spmUIComponentsBaseURL = 'CDEJ/jscript/SPMUIComponents/';

// Retrieves Static Content Server from SPM.
//
// The serverRootURL is set on the root document window so if a js bundle
// is requested by a UIM iframe the parent window is checked instead.
const serverRootURL =
window.curam || window.parent.curam
? window.curam.serverRootURL || window.parent.curam.serverRootURL || ''
: '';

// If a Static Content Server URL is not set, '../' must be prepended to
// the URL to get the correct relative path.
const spmUIComponentsRootURL = serverRootURL
? spmUIComponentsBaseURL
: `../${spmUIComponentsBaseURL}`;

// Concatenate the correct public path for use in webpack bundles.
const publicPath = `${serverRootURL}${spmUIComponentsRootURL}`;

export default __webpack_public_path__ = publicPath; // eslint-disable-line
19 changes: 19 additions & 0 deletions src/dynamicExports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

/*
Use when the main bundle is not on the same level as the script calling it.
Webpack will reference this path when emitting the chunks
*/
export const usePublicPath = async (path) => {
if (path) {
__webpack_public_path__ = path; // eslint-disable-line
}
};


/* Imports Carbon Addons dynamically */
export const requireCustomCarbonAddons = async () => {
const customCarbonAddons = await import(
/* webpackChunkName: "simple" */ './react'
);
return customCarbonAddons;
};
Binary file added src/examples/images/sample-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import "./scss/index.scss";




import 'regenerator-runtime/runtime';

import {
requireCustomCarbonAddons,
} from './dynamicExports';


export default {

requireCustomCarbonAddons,

};

// export { default as requireCustomCarbonAddons } from requireCustomCarbonAddons;


43 changes: 43 additions & 0 deletions src/react/Logo/Logo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import settings from '../settings';

const Logo = ({ children, className, size, ...other }) => {
const styleClass = cx(
`${settings.prefix}--logo`,
{
[`${settings.prefix}--logo--large`]: size === 'large',
[`${settings.prefix}--logo--medium`]: size === 'medium',
[`${settings.prefix}--logo--small`]: size === 'small',
},
className
);
return (
<div className={styleClass} {...other}>
{children}
</div>
);
};

Logo.propTypes = {
/**
* Pass in the image that will be rendered within the Logo
*/
children: PropTypes.node.isRequired,
/**
* Additional styling
*/
className: PropTypes.string,
/**
* Specify an optional size for the Logo. Defaults to 'medium'
*/
size: PropTypes.oneOf(['small', 'medium', 'large']),
};

Logo.defaultProps = {
size: 'medium',
className: undefined,
};

export default Logo;
Loading

0 comments on commit e7fb668

Please sign in to comment.